Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Evan Tsiklidis
Evan Tsiklidis 2018 年 4 月 3 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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