Iterating to Find the max value
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I am trying to find the maximum value of "Fm" that can be outputted from the programme. The programme is iterating from 1 through 359 degrees for that formula.
I know that i can just output all of the numbers and physically find which one is largest, but is there some sort of "if" statement I can make that will find it for me automatically?
Here is my code:
maxangle=359;
for muscleangle=1:maxangle;
a=0.15;
b=0.3;
c=0.6;
W=40;
Wo=60;
Fmy=(b*W+c*Wo)/a;
Fm=Fmy/sind(muscleangle);
Fmx=Fm*cosd(muscleangle);
disp (Fm);
disp(muscleangle);
end
I would really appreciate any help.
Thanks
0 件のコメント
回答 (3 件)
Andrei Bobrov
2011 年 11 月 21 日
muscleangle = 1:360;
a=0.15;
b=0.3;
c=0.6;
W=40;
Wo=60;
Fmy=(b*W+c*Wo)/a;
Fm=Fmy./sind(muscleangle);
Fmx=Fm.*cosd(muscleangle);
out = max(Fm(isfinite(Fm)))
Jan
2011 年 11 月 21 日
a=0.15;
b=0.3;
c=0.6;
W=40;
Wo=60;
Fmy=(b*W+c*Wo)/a;
Fm_max = -Inf;
for muscleangle=1:359
Fm = Fmy / sind(muscleangle);
Fmx = Fm * cosd(muscleangle);
if Fm > Fm_max % Or Fmx? [EDITED: FM_max->Fm_max]
Fm_max = Fm;
disp(Fm);
disp(muscleangle);
end
end
2 件のコメント
Jan
2011 年 11 月 21 日
@Stephen: This is a typo obviously. I think, it would not be to hard to find out, that I've written "Fm_max" at first and "FM_max" afterwards. But both need the same name.
I've interpreted "just output all of the numbers and physically find which one is largest" such that you know how to solve this using MAX already. Therefore I've posted the less efficient loop method using IF.
Daniel Shub
2011 年 11 月 21 日
a=0.15;
b=0.3;
c=0.6;
W=40;
Wo=60;
Fmy=(b*W+c*Wo)/a;
Fm_max = -Inf;
muscleangle=1:359;
Fm = Fmy./sind(muscleangle);
Fmx = Fm.*cosd(muscleangle);
Fm_max = max(Fm)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!