curve fit toolbox help system ODE and excel?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Renee
am 23 Okt. 2014
Kommentiert: Renee
am 30 Okt. 2014
Hi, I am trying to curve fit using the toolbox to a function which is a system of ODE. my data corresponds to one equation of the function. how can i specify this? Also, the tutorial seems to say you should put your data into the command line, but mine is in excel, is there some easier way? Thanks!
0 Kommentare
Akzeptierte Antwort
Matt Tearle
am 23 Okt. 2014
If I interpret your problem correctly, you have a system of ODEs with a parameter -- y' = f(t,y;c) -- and an Excel spreadsheet that has data for t and y3 (or whatever -- one of the components of y). You're trying to do a curve fit to determine c.
That's fun!
Here's an example that does that with the classic mass-spring system. I'm making some t and y data; you could read this from Excel with xlsread. You need to do this only once at the beginning, then you have the data to fit to.
% ---------------------------------------------------------------
% Make some data -- replace all this with a call to XLSREAD
m = 0.1*rand;
k = 4*rand;
w = 0.5*sqrt(4*k-m*m);
t = linspace(0,2*pi)';
y = exp(m*t/2).*cos(w*t) + 0.02*randn(size(t));
% ---------------------------------------------------------------
% Do curvefitting
cfit = lsqcurvefit(@myode,rand(2,1),t,y)
% See results
plot(t,y,'o',t,myode(cfit,t))
And here's the curve-fitting function:
function y = myode(c,x)
% Define ODE system with parameter c
f = @(t,y,c) [y(2);-c(1)*y(1)+c(2)*y(2)];
% Solve ODE system with given initial condition
[~,z] = ode45(@(t,y) f(t,y,c),x,[1;0]);
% Extract desired solution component
y = z(:,1);
13 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Global or Multiple Starting Point Search finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!