+ Post New Thread
Results 1 to 2 of 2

31st March 2020, 15:53 #1
 Join Date
 Jan 2018
 Posts
 1
 Helped
 0 / 0
 Points
 424
 Level
 4
MATLAB funstion "dsolve" gives complex terms
I am facing problem in using dsolve. The solution it gives has complex terms but my expected answer is completely real. Attached is the picture of the differential equation and its general solution which I am trying to get using MATLAB
Here is my code:
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==VccVr*sin(x+phi); % nonhomogenous second order DE Vs = dsolve(ode,x,'IgnoreAnalyticConstraints',1); Vs= simplify(Vs); pretty(Vs)
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
Vs(x)= (q^2/(1q^2))*Vr*Sin(phi+x)VccC5*cosqxi*C5*SinqxC6*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)/(1q^2)*Vr*sin(phi+x)

Advertisement

2nd April 2020, 12:28 #2
 Join Date
 Jan 2019
 Posts
 612
 Helped
 156 / 156
 Points
 3,332
 Level
 13
Re: MATLAB funstion "dsolve" gives complex terms
i am not a user of MATLAB
however:
in your "equation" ode = , the ode is a function of x, but x is wt.
did do you tell MATLAB that x = wt?
i used MATHEMATICA a few years ago to fit a sinusoidal curve
i also got imaginary answers when i did not expect them
first, the imaginary parts were very small, so it didn't matter (? not quite sure about that, even then)
second, i squared and square rooted one term  which removed a minus sign, but did not change the
appropriateness of the fit equation, and the imaginary terms disappeared.
i do not expect this makes any difference:
the text you posted had everything on the left side = 0
you gave MATLAB had left side == right side
as a user of MATLAB, you can determine is any of these items makes a difference or not
+ Post New Thread
Please login