Info
This question is closed. Reopen it to edit or answer.
How can I include the derivative of a function as an input to a function handle?
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
James Tursa
on 3 Apr 2018
Edited: James Tursa
on 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)
0 Comments
This question is closed.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!