Help with MATLAB symbolic toolbox

2 visualizzazioni (ultimi 30 giorni)
Scott Banks
Scott Banks il 25 Gen 2025
Risposto: Scott Banks il 26 Gen 2025
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

Risposta accettata

Torsten
Torsten il 25 Gen 2025
Modificato: Torsten il 25 Gen 2025
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)

Più risposte (2)

Paul
Paul il 25 Gen 2025
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 Commento
Walter Roberson
Walter Roberson il 25 Gen 2025
% 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 = 

Accedi per commentare.


Scott Banks
Scott Banks il 26 Gen 2025
Thank you, guys, for all your help!

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by