curve fit toolbox help system ODE and excel?

1 次查看(过去 30 天)
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!

采纳的回答

Matt Tearle
Matt Tearle 2014-10-23
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 个评论
Renee
Renee 2014-10-30
hopefully this link will work: new post I'm working on the random numbers thing.
Renee
Renee 2014-10-30
The output with random numbers looks the same.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Global or Multiple Starting Point Search 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by