Fitting differential equation (ode45) to data using lsqcurvefit

12 Ansichten (letzte 30 Tage)
Cho113578
Cho113578 am 19 Okt. 2017
Bearbeitet: Torsten am 19 Okt. 2017
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?

Antworten (1)

Torsten
Torsten am 19 Okt. 2017
Bearbeitet: Torsten am 19 Okt. 2017
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.

Kategorien

Mehr zu Matrix Computations 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!

Translated by