Substituting a function from a differential equation

조회 수: 5 (최근 30일)
Sean Thrasher
Sean Thrasher 2020년 7월 30일
답변: Surya Talluri 2020년 8월 7일
Hi, I am a beginner and I am learning symbolic math toolbox for MATLAB.
I have got a system of differential equations
and a definition for alpha:
where r = √(x^2 +y^2 +z^2).
My aim is to differentiate alpha with respect to t, and then substitute the differential equations to obtain
My code looks like this:
syms alpha(t) beta(t) r(t) x(t) y(t) z(t) t epsilon theta(t)
r(t) = sqrt((x(t))^2+(y(t))^2+(z(t))^2)
dtheta(t)=diff(theta(t),t)
alpha(t) = sqrt(( r+z(t))/(2*r))
beta(t) = (x(t)+ i*y(t))/sqrt(2*r*(r+z(t))) %I want to do the same for beta too, differentiate it w.r.t t and substitute the differential equations
diffeqn1 = epsilon*diff(x(t),t) == -y(t) - epsilon*dtheta(t)*z(t)
diffeqn2 = epsilon*diff(y(t),t) == x(t)
diffeqn3 = diff(z(t),t) == dtheta(t) * x(t)
diff(alpha(t),t)
But of course, I only get an expression involving the derivatives of x(t),y(t),z(t).
How can I make the program take diffeqn1 ,diffeqn2, diffeqn3 into consideration?
Any help would be massively appreciated.

답변 (1개)

Surya Talluri
Surya Talluri 2020년 8월 7일
I understand that you want to substitute diff(x(t),t), diff(x(t),t), diff(x(t),t) values in diff(alpha(t),t). You can use “isolate” function to obtain differentiation equations and substitute them in diff(alpha(t),t).
dx = diff(x(t),t);
dy = diff(y(t),t);
dz = diff(z(t),t);
diffeqn1 = epsilon*dx == -y(t) - epsilon*dtheta(t)*z(t);
diffeqn2 = epsilon*dy == x(t);
diffeqn3 = dz == dtheta(t) * x(t);
diffeqn1 = isolate(diffeqn1, dx);
diffeqn2 = isolate(diffeqn2, dy);
diffeqn3 = isolate(diffeqn3, dz);
dalpha = diff(alpha(t),t);
dalpha = subs(dalpha, {lhs(diffeqn1), lhs(diffeqn2), lhs(diffeqn3)}, {rhs(diffeqn1), rhs(diffeqn2), rhs(diffeqn3)});
You can refer to the following documentation for further understanding:

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by