Please login with a confirmed email address before reporting spam
Posted:
6 years ago
13.02.2018, 08:46 GMT-5
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:
6 years ago
15.02.2018, 04:31 GMT-5
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:
6 years ago
15.02.2018, 07:43 GMT-5
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
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAI4AAAAXCAQAAAB3nb8IAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAAAHgAAAB4AJ31WmAAAAAHdElNRQfoCAkKJBCac0MQAAADjklEQVRYw+2Z23mjMBBGj/ylAbWgFtgStCWQEkgJpAS5BFyCKQFKwCWYEqCE2QduAgQLWe/lYYcXPBIzo3+uSpTwn7bo8rcN+JfpheCoREW/x0iVKv1n4JjT2xfNNVIvOBYtD++3G97kE0AlGAAeki9lkfSv3lr/fS034Ibj4xXHVRHt0vJxTRNRz1bl9IPBUSx4mvtqn0Uo0OPvCofZkHlHiBdfV1jvlztv6UJHjMMSk4WsIMWRklERjbyTCiIcKdUKnGw6iMctaMb3hGRXrvjHR5NNsPayzDlbVy59jrqqADQ9JDiaQdPXFBVzcNCD4sW+BOkg2YdGEHj6Mkjn0AjEZIfts5P3PfeN4FPNo9SHHj256TUFOSYPseVGTQIqArn9RMYNo+xYb0ppF7Jy4kNVxaqCmHa14H/dYherlqzX0wJ9Y3nry1QM8qksFrhK6/EiLHooqxtkw+AAOalKaX8KDeQ4YkpQMblf2kd6KCvlLjAJCSXv0gYWNf63ZrH6PoNzKMpdEAs8cUQYGtIZr0uLe8fdSKsqVHHGIK0OJsOdBr2dgGS+DSs9KcU6Gb1EE6+8u22biKedF1AxJWCo5UHLjZvHG9KhZW/SiDY9aqiJlOEIlWj2omzDBqWVo6CV73INxkzQ4s2VlOtwmgvQykPZDgZp5VNaj/c5CjuqdmY2lg8Y55h9ygEj+aG9EzAZd0r5diBxfdqadTIeUwG5gJSAnWXkgqcMEaeM7qFJ5Solj4PgGODcEUGjqQ84rgYv7qIwOCoB8YbNy7h9XQInXsxja67cgcZxBeCGVkfgsb1TTpDU8s6VRBXK7u9jnkoBOFWC6aAZysAAziJyFryY3L8QrKgOmOboEhS50R6KnZCDfNJhf0stH3xgVbHrgnwmaaVJRV4RGU4z1PJQfR/fBSNMXWTVre6L0V/71wYBN+sVhmeo79DsXxEo1qPdQqujIAl3LOw4IRsa9NwOIgrc9IznFnCBm5HHoyIe2iSOjIaGbLopkXrTp+VOg0zHJ+WJ8Bz2Y2jm+rrbGkKF22rGwnQV2YUo2ZJCSobGDCBjJnfQzLZaHxy9Fjbnbc0x4+EOzjLTNHFu/8nrQxy2F0O6FVnB/WeN3BCT7cO3jssvaPili+dXnlf9set6sF0Pxe9kV9r7O8zvoxeBIzXloXbdkT3bskn6seDP0uuCkHi/m/yC5PR4nXjlo/7/92GbfgBn6EFLJVs30wAAAC10RVh0aWNjOmNvcHlyaWdodABDb3B5cmlnaHQgQXJ0aWZleCBTb2Z0d2FyZSAyMDExCLrFtAAAADF0RVh0aWNjOmRlc2NyaXB0aW9uAEFydGlmZXggU29mdHdhcmUgc1JHQiBJQ0MgUHJvZmlsZRMMAYYAAAAhdEVYdHBzOkhpUmVzQm91bmRpbmdCb3gAODV4MTQrMjYzKzYzNmahk+gAAAAedEVYdHBzOkxldmVsAFBTLUFkb2JlLTIuMCBFUFNGLTIuMEH5MxMAAAAASUVORK5CYII=)
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:
6 years ago
16.02.2018, 15:32 GMT-5
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:
6 years ago
19.02.2018, 02:38 GMT-5
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