Help with MATLAB symbolic toolbox

2 ビュー (過去 30 日間)
Scott Banks
Scott Banks 2025 年 1 月 25 日
回答済み: Scott Banks 2025 年 1 月 26 日
Hi there everyone,
I need some help with using the MATLAB symbolic tool box.
I have some symbolic expressions to manipulate and I am getting quite frustrated.
I have the paticular solution to a differential equation and need to find the coefficients C1 and C2.
% Set up symbolic variables
syms t C1 C2
% Set up parameters
K = 2.2167e+06;
M = 45.96;
wn = sqrt(K/M)
c = 0.5
% set up quadratic terms
a = 1
b = 2*c*wn
c = wn^2
% Solve for u
u1 = (-b + sqrt(b^2 - 4*a*c))/2
u2 = (-b - sqrt(b^2 - 4*a*c))/2
% Particalular solution to differential equation
yp = vpa(exp(-43.1357*t)*(C1*cos(74.7132*t) + C2*sin(74.7132*t)) == 0,4)
% The first derivitive of yp
dyp = vpa(diff(yp),4)
% Find the value of C1 interm of C2
C1 = vpa(solve(yp, C1),4)
% Sub C1 into equation dyp to have an expression in terms of C2 alone
eq = vpa(subs(dyp,C2,C1),4)
As you can see I obtain the value of C1 in terms of C2. I then want to plug this into equation "dyp". However, when I run the code for "eq", C1 is still in the expression. The expression should contain just C2's, and this is really frustrating. If equation "eq" contains just C2 values I can then solve for C2 - I hope this makes sense.
Is there a way around this. I have not very good at plug and chucking with long and messy equatons, so I am hoping MATLAB can help me out.
Thanks in advance,
Scott

採用された回答

Torsten
Torsten 2025 年 1 月 25 日
編集済み: Torsten 2025 年 1 月 25 日
Can't you use "dsolve" ?
If not, use
% Find the value of C1 interm of C2
C1_sol = vpa(solve(yp, C1),4)
% Sub C1 into equation dyp to have an expression in terms of C2 alone
eq = vpa(subs(dyp,C1,C1_sol),4)

その他の回答 (2 件)

Paul
Paul 2025 年 1 月 25 日
Hi Scott,
See below for solution
% Set up symbolic variables
syms t C1 C2
% Set up parameters
K = 2.2167e+06;
M = 45.96;
wn = sqrt(K/M);
c = 0.5;
% set up quadratic terms
a = 1;
b = 2*c*wn;
c = wn^2;
% Solve for u
u1 = (-b + sqrt(b^2 - 4*a*c))/2;
u2 = (-b - sqrt(b^2 - 4*a*c))/2;
% Particalular solution to differential equation
yp = vpa(exp(-43.1357*t)*(C1*cos(74.7132*t) + C2*sin(74.7132*t)) == 0,4)
yp = 
% The first derivitive of yp
dyp = vpa(diff(yp),4)
dyp = 
% Find the value of C1 interm of C2
C1 = vpa(solve(yp, C1),4)
C1 = 
To substitute the current value workspace variables into an expression call subs with the expression to be updated as the lone argument
% Sub C1 into equation dyp to have an expression in terms of C2 alone
% eq = vpa(subs(dyp,C2,C1),4)
eq = vpa(subs(dyp),4)
eq = 
  1 件のコメント
Walter Roberson
Walter Roberson 2025 年 1 月 25 日
% Set up symbolic variables
syms t C1 C2
Q = @(v) sym(v);
% Set up parameters
K = Q(22167)*Q(10)^2;
M = Q(4596)/Q(10)^2;
wn = sqrt(K/M);
c = Q(0.5);
% set up quadratic terms
a = Q(1);
b = 2*c*wn;
c = wn^2;
% Solve for u
u1 = (-b + sqrt(b^2 - 4*a*c))/2;
u2 = (-b - sqrt(b^2 - 4*a*c))/2;
% Particalular solution to differential equation
F1 = Q(431357)/Q(10)^4;
F2 = Q(747132)/Q(10)^4;
yp = exp(-F1*t)*(C1*cos(F2*t) + C2*sin(F2*t)) == 0;
% The first derivitive of yp
dyp = diff(yp)
dyp = 
% Find the value of C1 interm of C2
C1 = solve(yp, C1)
C1 = 

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


Scott Banks
Scott Banks 2025 年 1 月 26 日
Thank you, guys, for all your help!

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by