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

2 views (last 30 days)
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 Comments
Devyani Sankhe
Devyani Sankhe on 11 Dec 2021
Edited: Devyani Sankhe on 11 Dec 2021
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 on 11 Dec 2021
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

Sign in to comment.

Answers (1)

Chunru
Chunru on 11 Dec 2021
[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);

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!