Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How can I include the derivative of a function as an input to a function handle?

1 Ansicht (letzte 30 Tage)
Evan Tsiklidis
Evan Tsiklidis am 3 Apr. 2018
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Consider the following code snippet corresponding to the solution to the system of ordinary differential equations
da/dt = t*a/(a^2+b^2 + 1)
db/dt = (b-a)^2/(b^2+c^2+1)
dc/dt = t^2*c^2/(a^2+c^2+1)
clear;clc;
initial_conditions = [1 0 -1];
F=@(t,y) [t.*y(1)./(y(1).^2+y(2).^2+1);
(y(2)-y(1)).^2./(y(2).^2+y(3).^2+1);
t.^2.*y(3).^2./(y(1).^2+y(3).^2+1)];
[t y]=ode23tb(F,[0 2], initial_conditions);
plot(t, y(:,1), 'r', t, y(:,2), 'g', t, y(:,3), 'b')
where y(1) corresponds to a, y(2) corresponds with b, and y(3) corresponds with c. How can I include the additional differential equation, dz/dt = 5*da/dt, with z(0) = 2 ? I am not sure how to include this in the function handle since It's the derivative of the output of the first handle with respect to t, and not one of the state variables as the other equations are.
Thanks.

Antworten (1)

James Tursa
James Tursa am 3 Apr. 2018
Bearbeitet: James Tursa am 3 Apr. 2018
Currently you have a 3-element state vector, with the states being a, b, c. You simply use a 4-element state vector with the 4th state being z. Then your F would be:
F=@(t,y) [t.*y(1)./(y(1).^2+y(2).^2+1);
(y(2)-y(1)).^2./(y(2).^2+y(3).^2+1);
t.^2.*y(3).^2./(y(1).^2+y(3).^2+1);
5*t.*y(1)./(y(1).^2+y(2).^2+1)]; % <-- 5*da/dt
and your initial conditions would be:
initial_conditions = [1 0 -1 2]; % <-- added z(0)

Diese Frage ist geschlossen.

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by