Please login with a confirmed email address before reporting spam
Posted:
7 years ago
Feb 13, 2018, 8:46 a.m. EST
though i can do it in matlab using randsrc function. i can generate a matrix of any order comprising of zero and one according to a probability function. but cannot do it in comsol.
though i can do it in matlab using randsrc function. i can generate a matrix of any order comprising of zero and one according to a probability function. but cannot do it in comsol.
Please login with a confirmed email address before reporting spam
Posted:
7 years ago
Feb 15, 2018, 4:31 a.m. EST
i am still stuck on this. if somebody could help it will be really helpful.
i am still stuck on this. if somebody could help it will be really helpful.
Henrik Sönnerlind
COMSOL Employee
Please login with a confirmed email address before reporting spam
Posted:
7 years ago
Feb 15, 2018, 7:43 a.m. EST
Hi Zahid,
You do not really tell why you cannot use the built-in random function. If you just want a randomized variable over the domain to take the value 0 or 1 with an expected value of 0.2, you can write an expression like
Here rn1 is the built-in random function, but shifted so that it is uniform over the interval [0,1].
Regards,
Henrik
-------------------
Henrik Sönnerlind
COMSOL
Hi Zahid,
You do not really tell why you cannot use the built-in random function. If you just want a randomized variable over the domain to take the value 0 or 1 with an expected value of 0.2, you can write an expression like
rn1(X,Y)
Please login with a confirmed email address before reporting spam
Posted:
7 years ago
Feb 16, 2018, 3:32 p.m. EST
Dear Henrik.
Thanks alot for your response. I actually am working on phase field modeling for phase transformation. I want my initial domain to consist of Phase 'A' (20% of the material by area) with a value of 0 and another Phase 'B' (80% of the material by area). For this problem, I need to make a function that gives me these two discreet values randomly distributed. I hope you understood it now more clearly. I dont want to make two separate domains for both phases and assign two different functions for them.
Dear Henrik.
Thanks alot for your response. I actually am working on phase field modeling for phase transformation. I want my initial domain to consist of Phase 'A' (20% of the material by area) with a value of 0 and another Phase 'B' (80% of the material by area). For this problem, I need to make a function that gives me these two discreet values randomly distributed. I hope you understood it now more clearly. I dont want to make two separate domains for both phases and assign two different functions for them.
Henrik Sönnerlind
COMSOL Employee
Please login with a confirmed email address before reporting spam
Posted:
7 years ago
Feb 19, 2018, 2:38 a.m. EST
Hi Zahid,
The expression I wrote in my previous post does exactly that: Generates two discrete values randomly distrubuted. They will however also be randomly distributed within each element, and that may not be what you want.
If you for example want each element to have the value 1 or 0, then you have to feed the random function with the element number, rather that by the coordinates, as in my example.
If you want larger contiguous regions, then it is trickier.
Regards,
Henrik
-------------------
Henrik Sönnerlind
COMSOL
Hi Zahid,
The expression I wrote in my previous post does exactly that: Generates two discrete values randomly distrubuted. They will however also be randomly distributed within each element, and that may not be what you want.
If you for example want each element to have the value 1 or 0, then you have to feed the random function with the element number, rather that by the coordinates, as in my example.
If you want larger contiguous regions, then it is trickier.
Regards,
Henrik