"dsolve" gives some extra terms in the solution
2 views (last 30 days)
Show older comments
I am facing problem in using dsolve. Similar issue was also discussed in below link. I tried the suggestion given by Star Strider in question (https://in.mathworks.com/matlabcentral/answers/326248-dsolve-returns-imaginary-components-when-it-shouldnt-how-to-fix-this), but it does not work in my case or maybe I am doing something wrong. Here is my code:
syms Vs(x) w l C phi Vcc Vr
q= 1/(w*sqrt(l*C));
ode = w*w*l*C*diff(Vs,x,2)+Vs==Vcc-Vr*sin(x+phi); % non-homogenous second order DE
Vs = dsolve(ode,x,'IgnoreAnalyticConstraints',1);
Vs= simplify(Vs);
pretty(Vs)
This gives the solution
Vr sin(phi + x) - Vcc - C5 exp(#1) - C6 exp(-#1) + C Vcc l (w^2) + C C5 l (w^2) exp(#1) + C C6 l (w^2) exp(-#1)
----------------------------------------------------------------------------------------------------------
C l (w^2) - 1
x sqrt(-C l)
#1 == ------------
C l w
which after some simplication with hand gives the following:
Vs(x)= (q^2/(1-q^2))*Vr*Sin(phi+x)-Vcc-C5*cosqx-i*C5*Sinqx-C6*cosqx+i*C6*sinqx
If the DE is solved by hand it gives the following:
V(x)= C1*cos(q*x) + C2*sin(q*x) + Vcc + (q^2)/(1-q^2)*Vr*sin(phi+x)
The expected solution as calculated by hand does not contain any imaginary part. Moreover the solution given by dsolve does not fully match with the expected one. I don't undestand where I am doing wrong. Kindly help me to debug this.
6 Comments
darova
on 30 Mar 2020
I think there is something wrong in your hand calculations
V(x)= C1cosqxC2sinqx+Vcc-(q^2-1)/(q^2)*Vrsin(phi+x)
I wanted to calculate C1 and C2 and failed because when i tried to substitute x=0 all constants disappear
V(0) = Vcc-(q^2-1)/(q^2)*Vrsin(phi+0) % wrong?
Answers (2)
Star Strider
on 30 Mar 2020
Tell simplify to keep simplifying until it either meets the iteration limit or cannot simplify the expression further:
Vs= simplify(Vs, 'Steps',500);
pretty(Vs)
producing:
Vs =
Vcc + C1*exp((x*(-C*l)^(1/2))/(C*l*w)) + C2*exp(-(x*(-C*l)^(1/2))/(C*l*w)) + (Vr*sin(phi + x))/(C*l*w^2 - 1)
with the LaTeX version being:
darova
on 30 Mar 2020
Here is comparison of solutions. See script inside
8 Comments
darova
on 2 Apr 2020
Can't explain this. Looks like phenomena
Did you try to solve equations for C5 and C6 in original form?
-C5*cosqx-i*C5*Sinqx-C6*cosqx+i*C6*sinqx
Maybe during some calculations complex i disappears somewhere?
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!