Trigonometric functions using dsolve

17 ビュー (過去 30 日間)
Urmish Hemant Haribhakti Parikh
Urmish Hemant Haribhakti Parikh 2022 年 4 月 4 日
コメント済み: Walter Roberson 2022 年 4 月 5 日
This code works well. How can I use sin(theta2) instead of theta2. Its giving me error.
syms theta1(t) theta2(t) theta3(t)
ode1= diff(theta1)== 1+theta2-theta1;
ode2= diff(theta2)==1+ theta3-theta2;
ode3= diff(theta3)== theta2-theta3;
odes=[ode1;ode2; ode3];
S=dsolve(odes);
theta1Sol(t) = S.theta1;
theta2Sol(t)=S.theta2;
theta3Sol(t)=S.theta3;
cond1 = theta1(0) == 0.1;
cond2 = theta2(0) == 0.3;
cond3 = theta3(0) == 0.2;
conds = [cond1; cond2; cond3];
[theta1Sol(t),theta2Sol(t), theta3Sol] = dsolve(odes,conds)
theta1Sol(t) = 
theta2Sol(t) = 
theta3Sol = 
fplot(theta1Sol)
hold on
fplot(theta2Sol)
grid on
fplot(theta3Sol)
grid on
legend('theta1Sol','theta2Sol','theta2Sol','Location','best')
  7 件のコメント
Urmish Hemant Haribhakti Parikh
Urmish Hemant Haribhakti Parikh 2022 年 4 月 5 日
syms theta1(t) theta2(t) theta3(t)
ode1= diff(theta1)== 1+sin(theta2)-theta1;
ode2= diff(theta2)==1+ theta2-theta2;
ode3= diff(theta3)== theta2-theta3;
odes=[ode1;ode2; ode3];
S=vpasolve(odes);
theta1Sol(t) = S.theta1;
theta2Sol(t) = S.theta2;
theta3Sol(t) = S.theta3;
cond1 = theta1(0) == 0.1;
cond2 = theta2(0) == 0.3;
cond3 = theta3(0) == 0.2;
conds = [cond1; cond2; cond3];
[theta1Sol(t),theta2Sol(t), theta3Sol] = dsolve(odes,conds);
fplot(theta1Sol)
hold on
fplot(theta2Sol)
grid on
fplot(theta3Sol)
grid on
legend('theta1Sol','theta2Sol','theta2Sol','Location','best')
Urmish Hemant Haribhakti Parikh
Urmish Hemant Haribhakti Parikh 2022 年 4 月 5 日
How do I solve it using ode45 ? having a hard time

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2022 年 4 月 5 日
syms theta_1(t) sin_theta_2(t) theta_3(t)
ode1 = diff(theta_1) == 1 + sin_theta_2 - theta_1;
ode2 = diff(sin_theta_2) == 1 + theta_3 - sin_theta_2;
ode3 = diff(theta_3) == sin_theta_2 - theta_3;
odes = [ode1; ode2; ode3];
Snc = dsolve(odes)
Snc = struct with fields:
sin_theta_2: C1 + t/2 - exp(-2*t)*(C2 - exp(2*t)/4) theta_1: C1 + t/2 + exp(-t)*(C3 + exp(t)) + exp(-2*t)*(C2 - exp(2*t)/4) theta_3: C1 + t/2 + exp(-2*t)*(C2 - exp(2*t)/4)
theta_1_Sol_nocond(t) = simplify(Snc.theta_1)
theta_1_Sol_nocond(t) = 
theta_2_Sol_nocond(t) = simplify(asin(Snc.sin_theta_2))
theta_2_Sol_nocond(t) = 
theta_3_Sol_nocond(t) = simplify(Snc.theta_3)
theta_3_Sol_nocond(t) = 
cond1 = theta_1(0) == 0.1;
cond2 = sin_theta_2(0) == 0.3;
cond3 = theta_3(0) == 0.2;
conds = [cond1; cond2; cond3];
Sc = dsolve(odes, conds);
theta_1_Sol_cond(t) = simplify(Sc.theta_1)
theta_1_Sol_cond(t) = 
theta_2_Sol_cond(t) = simplify(asin(Sc.sin_theta_2))
theta_2_Sol_cond(t) = 
theta_3_Sol_cond(t) = simplify(Sc.theta_3)
theta_3_Sol_cond(t) = 
fplot(theta_1_Sol_cond)
hold on
fplot(theta_2_Sol_cond)
grid on
fplot(theta_3_Sol_cond)
grid on
legend('theta1Sol','theta2Sol','theta2Sol','Location','best')
figure
lowerbound = solve(Sc.sin_theta_2 == -1)
lowerbound = 
upperbound = solve(Sc.sin_theta_2 == 1)
upperbound = 
bounds = double([lowerbound, upperbound])
bounds = 1×2
-0.8426 1.0491
fplot(theta_1_Sol_cond, bounds)
hold on
fplot(theta_2_Sol_cond, bounds)
grid on
fplot(theta_3_Sol_cond, bounds)
grid on
legend('theta1Sol','theta2Sol','theta2Sol','Location','best')
  2 件のコメント
Torsten
Torsten 2022 年 4 月 5 日
編集済み: Torsten 2022 年 4 月 5 日
But this is not the solution to
ode1= diff(theta1)== 1+sin(theta2)-theta1;
ode2= diff(theta2)==1+ theta3-theta2;
ode3= diff(theta3)== theta2-theta3;
cond1 = theta1(0) == 0.1;
cond2 = theta2(0) == 0.3;
cond3 = theta3(0) == 0.2;
Walter Roberson
Walter Roberson 2022 年 4 月 5 日
At the time I was composing this, there had not been a reply indicating where the sin() was intended to go.

サインインしてコメントする。


Torsten
Torsten 2022 年 4 月 5 日
fun = @(t,theta) [1+sin(theta(2))-theta(1);1+theta(3)-theta(2);theta(2)-theta(3)];
theta0 = [0.1, 0.3, 0.2];
tspan = [0,2*pi]
[t,theta] = ode45(fun,tspan,theta0)
plot(t,theta)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by