My for loop is suppose to return the minimum value found in the for loop, but it just keeps returning the last found value. How can I make it return the minimum value found?
This is my code:
function m=myminimum (f,a,b); syms x ; for t=(a:b); m=subs(f(x),t); end m=min(m); end
Here is some sample data I have been running through the for loop along with what the answer it's suppose to be.
myminimum(@(x) x^2+1,-3,2) ans = 1
The answer my for loop provides is 5.
myminimum(@(x) x^2+6*x-3,-2,0) ans = -11
The answer my for loop provides is -3.
How do I make my for loop return the minimum value of the for loop and not just the last found value?
Thanks
Best Answer