Need help looking for local minimum on a parabola
Show older comments
I was wondering if anyone would be able to help me out with this.. I need to use a function M file to determine the local minimum of a parabola where the critical points can also qualify as a minimum. Here is my code. Currently it is returning values without error but the values don't match any of my test data given by my instructor.
if true
function c = myminimum(f, a, b)
syms x v w;
w=solve(diff(f(x)));
v=subs(f(x), w);
if (a<v && a<b);
c=a;
elseif (b<v && b<a);
c=b;
else c=v;
end
end
Here is the test data if that helps:
if truea = myminimum(@(x) x^2+1,-3,2)
a = 1
a = myminimum(@(x) x^2+6*x-3,-2,0)
a = -11
a = myminimum(@(x) -2*x^2+10*x,3,8)
a = -48
a = myminimum(@(x) -x^2+2*x+1,5,6)
a = -23
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!