ans =
Solving DE initial value problem symbolically in Matlab
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (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)
Catégories
En savoir plus sur Numeric Solvers dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
