Fitting differential equation (ode45) to data using lsqcurvefit

조회 수: 12 (최근 30일)
Cho113578
Cho113578 2017년 10월 19일
편집: Torsten 2017년 10월 19일
I'm trying to fit an ode to data. For now I only have data I generated, so I know if I'm fitting it correctly. I found another thread about fitting ode to data using lsqcurvefit and followed that but couldn't get my code to give me the correct parameters.
Here is my code:
a = 1.5;
sa = .8;
n = .3;
% generates the data I will fit to
func = @(t,x) = ((1-x)*sa*(x^a)) - (x*(1-sa)*((1-x)^a));
tspan = 1:40;
[t1, x1] = @ode45(func, tspan, n);
% trying to find a and sa values that will fit the data generated
x0 = [.3 .3];
v = lsqcurvefit(@ASModelODE, x0, t1, x1);
function s = ASModelODE(v,t)
% ode:
% dx/dt = (1-x)*sa*x^a - x*(1-sa)*(1-x)^a
% variables:
% x
% parameters:
% v(1) = sa, v(2) = a;
x0 = [0.1 0.1];
diffeq = @(t,x) (1-x).*v(1).*x.^v(2) - x.*(1-v(1)).*(1-x).^v(2);
[T, Sv] = ode45(diffeq, t, x0)
s = Sv(:,1);
end
when I run this I get errors like "Complex sparse QR is not yet available" and it also gives me imaginary fit parameters most of the times.
What am I doing wrong?

답변 (1개)

Torsten
Torsten 2017년 10월 19일
편집: Torsten 2017년 10월 19일
Most probably, the solution of your differential equation T becomes greater than 1. This will turn (1-T)^v(2) into a complex number.
Best wishes
Torsten.

카테고리

Help CenterFile Exchange에서 Matrix Computations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by