ODE Classes: Numerical Integration

조회 수: 5 (최근 30일)
kileigh palmer
kileigh palmer 2021년 9월 15일
답변: William Rose 2021년 9월 17일
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