"dsolve" gives some extra terms in the solution

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

darova
darova 2020년 3월 30일
Did you try to plot it?
Mir Nazir
Mir Nazir 2020년 3월 30일
No I haven't since I have too many unknowns.
darova
darova 2020년 3월 30일
What C1 and C2 represents? I suppose they are initial conditions (positions and veloctity)?
The same as C5 and C6
Mir Nazir
Mir Nazir 2020년 3월 30일
C1 and C2 are constants of general solution of the differential equation in question. C1 and C2 will be calculated using initial conditions afterwards. First I wanted to have a general solution(homogenous + particular solution) of the equation. Yes, C1,C2 are same as C5, C4.The latter being generated by Matlab itself.
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?
Mir Nazir
Mir Nazir 2020년 3월 30일
I apologise. There is + sign in between c1cosqx and c2 sinqx. It is a typographical error I have corrected it in the poriginal post.

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2020년 3월 30일

1 개 추천

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:

댓글 수: 2

Mir Nazir
Mir Nazir 2020년 3월 30일
Actually I don't have any complex part in my expected answer which is from an IEEE transaction article and also coincides with my hand calculations. I have attached the screenshot of the equation I am trying to solve along with its answer.
Mir Nazir
Mir Nazir 2020년 4월 1일
Any suggestions?

댓글을 달려면 로그인하십시오.

darova
darova 2020년 3월 30일

0 개 추천

Here is comparison of solutions. See script inside

댓글 수: 8

Mir Nazir
Mir Nazir 2020년 3월 30일
Thank you so much for pointing out the error. I am sincerly sorry. I have re-calculated the results and have accordingly edited the post. This solution does coincide with that given by dsolve using your script (plot and script attached). But the problem of imaginary terms in the general solution still persists.
Mir Nazir
Mir Nazir 2020년 4월 1일
@darova looking forward for your valuable suggestions.
darova
darova 2020년 4월 1일
편집: darova 2020년 4월 1일
The best i can
-C5*cosqx-i*C5*Sinqx-C6*cosqx+i*C6*sinqx
i*sin(qx)*(C6-C5) - cos(qx)*(C6+C5)
% C1 = i*(C6-C5)
% C2 = -(C6+C5)
C1*sin(qx) + C2*cos(qx)
Mir Nazir
Mir Nazir 2020년 4월 2일
Thank you darova. Is my code correct?
darova
darova 2020년 4월 2일
It looks similar now. I think so
Mir Nazir
Mir Nazir 2020년 4월 2일
편집: Mir Nazir 2020년 4월 2일
But as per explanation above the value for C1 is complex then but actually it is not. I am attaching the solutions for c1 and c2 as well
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?
Mir Nazir
Mir Nazir 2020년 4월 2일
Thanks for the reply. I will try that.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

질문:

2020년 3월 30일

댓글:

2020년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by