Iterating to Find the max value
1 view (last 30 days)
Show older comments
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 Comments
Answers (3)
Andrei Bobrov
on 21 Nov 2011
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
on 21 Nov 2011
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 Comments
Jan
on 21 Nov 2011
@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
on 21 Nov 2011
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!