Optimization Of Function, Curve Fitting

Mike Martin

Mike Martin (view profile)

さんによって質問されました 2015 年 1 月 19 日

Alan Weiss (view profile)

さんによって 回答されました 2019 年 1 月 7 日
t_ind1(k,ii) = (3 * v_th^2 * R1 / s(ii)) / (w_sync * ((r_th + R1/s(ii))^2 + (x_th + L1)^2) );
I want to solve for the values of v_th, R1, r_th, x_th, and L1
I know that s varies from 0 - 1 evenly...I know the value for w_sync...and I Have Data points for (S vs t_ind)
In other words if i am given a curve, and i extract the data points from the curve, put them into matlab vector, and i know what the equation is to produce the curve, how can i spit back the values which produce given curve. (v_th, R1, r_th, x_th, and L1)

0 件のコメント

サインイン to comment.

3 件の回答

Titus Edelhofer (view profile)

2015 年 1 月 19 日

Hi Mike,
if you have the Optimization Toolbox available, take a look at the function
doc lsqcurvefit
It is exactly for this kind of problems. Your vector "s" is the "xdata", whereas the "t_ind" is the ydata. The parameter v_th, R1, r_th, x_th and L1 form the vector of unknowns "x".
Titus

0 件のコメント

サインイン to comment.

collinst (view profile)

2019 年 1 月 7 日

What am I doing wrong here?
I made up some data, then used lsqcurvefit to see if it found the real parameters, but it fell far from it...
Thanks.
xdata = (-10:0.1:10);
b = 0; %p(1)
a = 3; %p(2)
w = 0.5; %p(3)
for i = 1:length(xdata)
ydata(i) = (xdata(i)+b) * a * w * (exp(1)^-(w*(xdata(i)+b)^2));
end
fun = @(p,xdata)(xdata+p(1)) * p(2) * p(3) .* (exp(1).^-(p(3).*(xdata+p(3)).^2));
p0 = [b a w];
p = lsqcurvefit(fun,p0,xdata,ydata);
for i = 1:length(xdata)
yt(i) = (xdata(i)+p(1)) * p(2) * p(3) * (exp(1)^-(p(3)*(xdata(i)+p(3))^2));
end
plot(xdata,ydata,'ok')
hold on
plot(xdata,yt,'-r')

0 件のコメント

サインイン to comment.

Alan Weiss (view profile)

2019 年 1 月 7 日

Please don't ask a new question as an answer. Instead, start a new question.
But to answer your question, you have two typos:
fun = @(p,xdata)(xdata+p(1)) * p(2) * p(3) .* (exp(1).^-(p(3).*(xdata+p(3)).^2));
% Should be
fun = @(p,xdata)(xdata+p(1)) * p(2) * p(3) .* (exp(1).^-(p(3).*(xdata+p(1)).^2));
% Note the last p is p(1), not p(3)
%
% Simlarly,
yt(i) = (xdata(i)+p(1)) * p(2) * p(3) * (exp(1)^-(p(3)*(xdata(i)+p(3))^2));
% should be
yt(i) = (xdata(i)+p(1)) * p(2) * p(3) * (exp(1)^-(p(3)*(xdata(i)+p(1))^2));
Alan Weiss
MATLAB mathematical toolbox documentation

0 件のコメント

サインイン to comment.