ODE Classes: Numerical Integration

1 次查看(过去 30 天)
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

回答(1 个)

William Rose
William Rose 2021-9-17
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.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by