Help with MATLAB symbolic toolbox
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,
ScottHi 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 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 symbolic MATLAB Answers — New Questions