ODE Classes: Numerical Integration

3 visualizaciones (últimos 30 días)
kileigh palmer
kileigh palmer el 15 de Sept. de 2021
Respondida: William Rose el 17 de Sept. de 2021
Hi all!
I'm working on a class to run a two compartment system for fluids. I'm trying to solve an ODE with a Jacobian. When I was first running it, my main problem is there were too many outputs. When I tried switching the RHS to a column operator there is a problem with the column operator. I attached snips of the code below: Thanks for any help!
Too many outputs:function Num_Trajectory = get.Numerical(obj)
A = [-obj.ke1+obj.k1 obj.k2*(obj.V2/obj.V1); obj.k1*(obj.V1/obj.V2) -obj.k2] % This is the jacobian of the ODE.
Jacobian = @(t,x)A; % Rewrite the jacobian as a function.
RHS = @(t,x)A*x; % This is the RHS of the ODE.
ode_options = odeset('Jacobian',Jacobian); % Load the jacobian into the ODE options.
[~,Num_Trajectory] = ode23s(RHS,obj.tarray,obj.C01,ode_options); % Solve ODE for trajectory.
end
Colon Operator:
function Num_Trajectory = get.Numerical(obj)
% In this function, we set up the NUMERICAL trajectory
A = [-obj.ke1+obj.k1 obj.k2*(obj.V2/obj.V1); obj.k1*(obj.V1/obj.V2) -obj.k2] % This is the jacobian of the ODE.
Jacobian = @(t,x)A; % Rewrite the jacobian as a function.
RHS = @(t,x)A*x; % This is the RHS of the ODE.
ode_options = odeset('Jacobian',Jacobian); % Load the jacobian into the ODE options.
[tarray,Num_Trajectory] = ode45(RHS(:),obj.tarray,obj.C01,ode_options); % Solve ODE for trajectory.
end

Respuestas (1)

William Rose
William Rose el 17 de Sept. de 2021
says the Jacobian option is not compaptible with ode45(). Maybe that explains the failure of the second code fragment, which uses ode45(). 'Jacobian' is compatible with ode23s(), so it does not explain the failure of the first example, which calls ode23s().
Would you provide the differential equations and the equations of the Jacobian for this system of two variables? It would be easier to understand.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by