Gives the specific parameter value as set of value instead one value.

1 次查看(过去 30 天)
Hello guys,
I am using two variable named as "P" and "R" in the my routine with fix value. Now, i would like to use multiple set of value instead of one value and caculate the final optimal solution based on that range.
Practical explanation:
What i am using
P= 12
R=18
and using these value in my routine (Routine made of different formulas)
So, now i would like to give value are as
P= 2 to 30
R= 6 to 25
So finally, i would like to do it this two things
1)Calculate the answer from routine at each P (2 to 30) and respective R (6 to 25) value , how can i do it ?
2)Practically, I knows the what answer range from routine is suitable for me. Answer should be in the range of 10 to 12. If P and R parameters from the above set gives the asnwer in the range of 10 to 12, then routine should show me those respective P and R values at the end. So, i can use it those best P and R values in the real life.
Explanation: the Answer range is suitable for me (10 to 12)
If any of P and R values able to satisfy this condition (If answer from the routine gives the value in between 10 to 12) then those values of P and R should show at the end .
Do you think, it is possible ? Any solutions from your side, will be gratly appreciable.
Thanks a lot
Devyani
  2 个评论
Devyani Sankhe
Devyani Sankhe 2021-12-11
编辑:Devyani Sankhe 2021-12-11
Do you think, it is possible ? as you are expert from the matlab. I am not using Matlab too much. Any solutions from your side, will be highly appreciable.
Thanks a lot
Devyani
Devyani Sankhe
Devyani Sankhe 2021-12-11
Do you think, it is possible ? as you are expert from the matlab. I am not using Matlab too much. Any solutions from your side, will be highly appreciable.
Thanks a lot
Devyani

请先登录,再进行评论。

回答(1 个)

Chunru
Chunru 2021-12-11
[Pgrid, Rgrid] = meshgrid(2:30, 6:25); % all combinations of P and R values
z = zeros(size(Pgrid));
for i=1:size(Pgrid, 1)
for j=1:size(Pgrid, 2)
P = Pgrid(i, j);
R = Rgrid(i, j);
% Your function
z(i, j) = your_function(P, R);
end
end
[zmin, idx] = min(z, 'all');
pmin = P(idx);
rmin = R(idx);

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by