Info

This question is closed. Reopen it to edit or answer.

Ι have a problem finding a minimum

2 views (last 30 days)
joanna zappa
joanna zappa on 6 Jan 2016
Closed: MATLAB Answer Bot on 20 Aug 2021
I created a fuction by writting
function [y]=h(x)
y=(x^8+P(x))^2
end
and I saved it as h.m then I wrote
[x,fval]=fminsearch(h,[2,3])
and it says its error FYI P(x) is a polynomial which i created in the main file
  4 Comments

Answers (2)

jgg
jgg on 6 Jan 2016
It looks like the issue is that you have not passed P into your function. You probably want something like this instead:
P=polyfit(X,Y.',7);
func = @(x)h(x,P);
[x,fval]=fminsearch(func,[2,3])
where you define in your h.m file
function [y]=h(x,P)
p = polyval(P,x);
y=(x^8+p)^2
end

Walter Roberson
Walter Roberson on 6 Jan 2016
It sure is easier when people do not ask duplicate questions...

This question is closed.

Community Treasure Hunt

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

Start Hunting!