Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

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

回答(1 个)

James Tursa
James Tursa 2018-4-3
编辑:James Tursa 2018-4-3
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)

此问题已关闭。

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by