How to plug in one symbolic equation into another

조회 수: 17 (최근 30일)
R Tarbell
R Tarbell 2016년 12월 23일
편집: Aylin 2016년 12월 27일
If I have a system of differential equations:
(1) d A(t) / dt = 2*A(t)
(2) d B(t) / dt = 3*B(t)
And now, I also have:
(3) C(t) = A(t) + (B(t)^2)
--> I tell Matlab to differentiate C(t):
d C(t) / dt = A'(t) + 2*B(t)*B'(t)
where A'(t) = d A(t) / dt, same for B'(t)
How do I tell Matlab to "plug in" for C'(t) using equations 1 and 2?

채택된 답변

Aylin
Aylin 2016년 12월 27일
편집: Aylin 2016년 12월 27일
Hello,
The subs function can be used to "plug in" values for the C'(t) equation.
In this answer, I use the Symbolic Math toolbox syntax from MATLAB R2016b. If you are using a previous version of MATLAB, you may have to adjust the syntax before using this code.
To elaborate further on your example, if A, B, and C are defined as symbolic functions of t:
syms A(t) B(t) C(t)
and eqA, eqB, eqC, and eqDC are the defined symbolic equations:
eqA = diff(A) == 2*A
eqB = diff(B) == 3*B
eqC = C == A + (B*B)
eqDC = diff(eqC)
then the subs function can be used as follows to substitute eqA for dA/dt:
eqDC_subA = subs(eqDC, diff(A), eqA)
and can be used for eqB too:
eqDC_subA_subB = subs(eqDC_subA, diff(B), eqB)
Please refer to the Symbolic Math Toolbox documentation for the subs function for more information:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by