Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Optimization Of Function, Curve Fitting

3 Ansichten (letzte 30 Tage)
Mike Martin
Mike Martin am 19 Jan. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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)

Antworten (3)

Titus Edelhofer
Titus Edelhofer am 19 Jan. 2015
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

collinst
collinst am 7 Jan. 2019
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')

Alan Weiss
Alan Weiss am 7 Jan. 2019
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

Diese Frage ist geschlossen.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by