dsolve returns imaginary components when it shouldnt..how to fix this?

I am having trouble with solving 2nd order differential equation with 'dsolve':
q=1*10^3; %N/m
L=2; %m
E=200*10^9; %Pa
I=177*10^-8; %m^4
syms W(x)
W=dsolve('D2W=(1/(E*I))*((-A*x)+q*((x^2)/2))','x')
which returns solution
% solution
W =- (q*exp(-1)*x^4*1i)/24 + (A*exp(-1)*x^3*1i)/6 + C3*x + C4
when the solution should have zero imaginary components since solving by hand gives me:
% by hand
W2=(1/(E*I))*(-A*(x^3)/6+q*(x^4)/24)+C0*x+C1
Any explanation or advice?

 采纳的回答

With this code, I get a real result (in R2016b, and assuming ‘A’ is a scalar):
syms W(x) A
q=1*10^3; %N/m
L=2; %m
E=200*10^9; %Pa
I=177*10^-8; %m^4
D2W = diff(W,x,2);
W=dsolve(D2W==(1/(E*I))*((-A*x)+q*((x^2)/2)),x, 'IgnoreAnalyticConstraints',1)
W =
(34739631023935125*x^4)/295147905179352825856 - (277917048191481*A*x^3)/590295810358705651712 + C1*x + C2

3 个评论

Hello,
I am facing the same problem. I tried the suggestion given by Star Strider, 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 - C21 exp(#1) - C22 exp(-#1) + C Vcc l w + C C21 l w exp(#1) + C C22 l w exp(-#1)
----------------------------------------------------------------------------------------------------------
2
C l w - 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)*VrSin(phi+x)-Vcc-C5cosqx-C5iSinqx-C6cosqx+C6isinqx
If the DE is solved by hand it gives the following:
V(x)= C1cosqxC2sinqx+Vcc-(q^2-1)/(q^2)*Vrsin(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 dont undestand where I am doing wrong. Kindly help me to debug this.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by