ans =
Solving DE initial value problem symbolically in Matlab
Show older comments
Hello, I'm trying to solve a differential equation IVP symbolically with MATLAB, but my answer is different than the actual answer. Am I doing something wrong?
syms x
dsolve('x*Dy+y=-sin(x)','y(pi/2)=0')
Gives the answer as:
exp(-t/x)*exp(pi/(2*x))*sin(x) - sin(x)
But the actual answer should be:
-(x*sin(x)-cos(x))/x^2
Accepted Answer
More Answers (1)
By default, y is assumed a function of t:
syms x y(t)
sol(t) = dsolve('x*Dy+y=-sin(x)','y(pi/2)=0')
simplify(x*diff(sol,t)+sol(t)+sin(x))
sol(pi/2)
... but you want y as a function of x:
syms y(x)
sol(x) = dsolve(x*diff(y,x)+y==-sin(x),y(pi/2)==0)
simplify(x*diff(sol,x)+sol+sin(x))
sol(pi/2)
Categories
Find more on Numeric Solvers 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!