How can I make function and find minimum
17 views (last 30 days)
Show older comments
E = problem_energy;
V = problem_volume;
[p,~,mu]=polyfit[V,E,6);
Now I have coefficient in p 1x6 How can I make polynomial equation with this and find minimum? I want to use fminsearch
0 Comments
Answers (1)
Star Strider
on 3 Dec 2014
Use the polyder function to get the first derivative (and, if you want to be efficient, the second derivative as well), then use the roots function and basic calculus to find the minimum.
Example:
p = polyfit([-1:0.01:2], cos(-1:0.01:2),6); % Polynomial Coefficients
d1p = polyder(p); % First Derivative
d2p = polyder(d1p); % Second Derivative
ips = roots(d1p); % Inflection Points
xtr = polyval(d2p, ips); % Evaluate ‘d2p’ at ‘ips’
minpts = ips((xtr > 0) & (imag(xtr)==0)); % Find Minima
x = linspace(min(ips)-5,max(ips)+5);
ep = polyval(p,x);
figure(1)
plot(x, ep, '-r')
hold on
plot(minpts, polyval(p,minpts), 'bp')
hold off
grid
0 Comments
See Also
Categories
Find more on Polynomials 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!