Info
此问题已关闭。 请重新打开它进行编辑或回答。
Ι have a problem finding a minimum
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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
0 个评论
Walter Roberson
2016-1-6
Answered in duplicate Question http://uk.mathworks.com/matlabcentral/answers/262900-have-a-problem-finding-a-minimum
It sure is easier when people do not ask duplicate questions...
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!