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.
댓글 수: 0
답변 (1개)
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)
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!