Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Ι have a problem finding a minimum

1 回表示 (過去 30 日間)
joanna zappa
joanna zappa 2016 年 1 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件のコメント
joanna zappa
joanna zappa 2016 年 1 月 6 日
P=polyfit(X,Y.',7)
Walter Roberson
Walter Roberson 2016 年 1 月 6 日
Duplicated by later http://uk.mathworks.com/matlabcentral/answers/262900-have-a-problem-finding-a-minimum which has an answer, so I am merging into that

回答 (2 件)

jgg
jgg 2016 年 1 月 6 日
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 2016 年 1 月 6 日
It sure is easier when people do not ask duplicate questions...

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by