optimalization of non linear function, Inputs must be a scalar and a square matrix
1 次查看(过去 30 天)
显示 更早的评论
Dear Matlab users, I'm a newbie in Matlab, and try to solve follewing problem.
I try to optimize function for data :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153987/image.jpeg)
I need to use simplex method to find parameter a,b,c, and r (in script (p1)... (p4))
The problem is that I use wrong bracket or something similar.
format compact
format long
xdata = [0.00,0.20,0.40,0.60,0.80,1.00,1.20,1.40,1.60,1.80,2.00,2.20,... 2.40,2.60,2.80,3.00,3.20,3.40,3.60,3.80,4.00,4.20,4.40,4.60,4.80,5.00];
ydata = [0.007,0.041,0.165,0.449,0.816,0.982,0.741,0.212,-0.362,-0.808,-0.975,... -0.774,-0.290,0.290,0.775,0.982,0.849,0.527,0.237,0.077,0.018,0.003,0.000,0.000,0.000,0.000];
%Function to calculate the sum of residuals for our a given parameters
fun = @(p) sum((ydata - (-1*(p(1)-p(2)*((xdata)-p(3)).^4)*exp(-p(4)*((xdata)-p(3).^2)))).^2) %starting guess for our parameters pguess = [1.0,12.0,1.03,2.4];
%optimise [p,fminres] = fminsearch(fun,pguess)
Does anybody know how to around this?
Thank you
P.
0 个评论
回答(1 个)
Alan Weiss
2014-8-5
It would be easier to read your code if you would use the {}Code button to format all of it. And it would be easier to diagnose your problem if you would give us the error message that MATLAB issues.
That said, it seems to me that you forgot a . in the .* by the exponential term:
...p(3)).^4)*exp(-p(4)*((...
should be
...p(3)).^4).*exp(-p(4)*((...
Alan Weiss
MATLAB mathematical toolbox documentation
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!