optimalization of non linear function, Inputs must be a scalar and a square matrix
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Alan Weiss
on 5 Aug 2014
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
1 Comment
See Also
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!