I am a beginner to matlab. kindly help me with the error "Error using fit_simp (line 2) Not enough input arguments".
1 view (last 30 days)
Show older comments
i was trying to write the code by transforming the answr given at the link http://www.mathworks.com/matlabcentral/answers/97439-how-do-i-fit-an-arbitrary-function-to-data-using-lsqnonlin-in-optimization-toolbox to my situation and i got the error as above. help me please to run this code. i want to do non linear least square minimization using levenberg marquardt method.
function diff = fit_simp(x,t,s)
Q=x(1);
T=x(2);
r=x(3);
S=x(4);
diff = ((Q/4/pi/T)*(-0.5772-log(r^2*S/4/T/t)+(r^2*S/4/T/t)-(r^2*S/4/T/t)/4)-s);
t = [1 2 3 4 5 7 9 15 20 30 40 50 70 90 130 160 200 240];
s = [0.89 .81 .76 .68 .64 .56 .49 .55 .38 .34 .28 .21 .17 .14 .10 .08 .05 0.03];
x0 = [.1;500;1;.05]';
x=lsqnonlin(@fit_simp,x0,[],[],[],t,s);
Y_new = (x(1)/4/pi/x(2))*(-0.5772-log(x(3)^2*x(4)/4*x(2)*t)+(x(3)^2*x(4)/4*x(2)*t)-(x(3)^2*x(4)/4*x(2)*t)/4);
plot(t,s,'+r',t,Y_new,'b');
0 Comments
Answers (2)
Walter Roberson
on 27 Jan 2016
The example there is quite outdated. You need
x = lsqnonlin(@(x) fit_simp(x,t,s),x0,[],[],[]);
Also, you should not name a variable "diff" as that is confusing and interfers with the use of the diff() function.
Make sure that your lines from t = [....] onward are in a different file, not in fit_simp.m . For example you could put those lines to the end into fit_driver.m and then you would invoke fit_driver in order to run the code
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!