find the solutions of h(x)=(x^8+P(x))^2 which give local minimum (fminsearch).....any help?

i dont know what function i have to write and also when i write xmin=fminsearch(.....) what i must write inside the space??

2 Comments

What is P(x) in your example? The easiest way to do this is to call an anonymous function:
x0 = 0; %for example
h = @(x)((x^8 + P(x))^2);
x = fminsearch(h,x0);
But this depends on what P(x) is here. If fminsearch is not required, you might consider something like lsqnonlin instead.
ok thank you..doing it by this way i dont have to create a function?

Sign in to comment.

 Accepted Answer

If P(x) is a 7-degree polynomial derived from polyfit:
p = randi(9, 1, 7); % Create Data (Polynomial Coefficients)
f = @(x,p) x.^8 + polyval(p,x).^2; % Function
x0 = 2; % Initial Estimate For ‘x’
[xmin,fval] = fminsearch(@(x)f(x,p), x0); % Find Minimum
You have likely gotten ‘p’ from something other than randi, but I had to create something to test the code.

2 Comments

it shows me an error Error in fminsearch (line 190) fv(:,1) = funfcn(x,varargin{:});
It ran for me (in R2015b) without error, or I’d not have posted it.
I don’t understand that error. There must be more to it.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!