Reputation: 219
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?
Upvotes: 1
Views: 114
Reputation: 1190
It really depends on the function of a, a=f(T)
. If you can take the derivative of f(T)
I suggest you include a
as another state, for instance X(3)
and then you can access it from the X
argument in xprime
easily, plus it will help Matlab determine the proper step size during integration:
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)
% X(3) = test parameter
%%% ODE
a = 10;
Yo = 0.4; %Just some Constant
dx(1) = (X(1))*(1 - X(1)^(a) - Yo*(X(2))));
dx(2) = sin(t);
dx(3) = ....
%%%%%%%
xprime = [dx(1) dx(2) dx(3)]';
end
Second method is to create a function(-handle) for a=f(T)
and call it from within xprime
:
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 = f_a(t,X);
Yo = 0.4; %Just some Constant
dx(1) = (X(1))*(1 - X(1)^(a) - Yo*(X(2))));
dx(2) = sin(t);
%%%%%%%
xprime = [dx(1) dx(2)]';
end
function a = f_a(t,X)
return 10; % You might want to change this.
end
If possible go with the first variant which is creating another state for a
.
Upvotes: 1