Constraining a variable value
古いコメントを表示
I am constraining constants for the dynamics of an autonomous system that I am simulating. Within a for loop of 100 iterations, I would like to give "a" a random value greater than zero, "b" a random value greater than 1/a, and "c" a random value greater than 0.5. I have an idea for the code of "a" but I am confused on how to constrain "b" and "c" so that they are random values specifically greater than 1/a and 0.5. Here is what I have for my code right now:
AS= rand(1, 200)*1000;
for ii = 1:100
a = AS(ii);
b=1/a;
c=???
end
Any suggestions on this issue are greatly appreciated. Thank you.
5 件のコメント
Steven Lord
2021 年 9 月 27 日
You've told us the lower limits for the values the variables can take on, but what are the upper limits? Is it 1, Inf, a function of one of the other variables like b's lower limit is a function of a, etc.?
Also what distribution do you want to draw the values from?
Matthew Tortorella
2021 年 9 月 27 日
Image Analyst
2021 年 9 月 28 日
@Matthew Tortorella, are you ever going to try my suggestion below?
Matthew Tortorella
2021 年 9 月 28 日
Matthew Tortorella
2021 年 9 月 28 日
回答 (1 件)
Image Analyst
2021 年 9 月 27 日
編集済み: Image Analyst
2021 年 9 月 27 日
b = 1/a;
b = max([b, 0.5]); % Make sure b is > 0.5
c = a + (b-a) * rand;
c = max([c, 0.5]); % Make sure c is > 0.5
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!