Lets say I have a function file of the ODE that goes like this
function xprime = RabbitTemp(t,X)
% Model of Rabbit Population
% where,
% Xo = Initial Population of Rabbits
% X(1) = Population density of Rabbit
% X(2) = Temperature T (that varies with time)
% a = test parameter
%%% ODE
a = 10;
dx(1) = (X(1))*(1 - a*X(1) - 3*(X(2))));
dx(2) = sin(t);
%%%%%%%
xprime = [dx(1) dx(2)]';
end
But what if I would like parameter a to vary as temperature X(2) varies, as the ODE solver calculates.
I understand I would first have to create some data between a and X(2) and interpolate it. But after that I'm not very sure what's next. Could any one point me in the right direction?
Or is there any other way?
It really depends on the function of a,
a=f(T)
. If you can take the derivative off(T)
I suggest you includea
as another state, for instanceX(3)
and then you can access it from theX
argument inxprime
easily, plus it will help Matlab determine the proper step size during integration:Second method is to create a function(-handle) for
a=f(T)
and call it from withinxprime
:If possible go with the first variant which is creating another state for
a
.