![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/741944/image.png)
ODE Classes: Numerical Integration
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
William Rose
am 17 Sep. 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/741944/image.png)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!