How do I use dsolve within a for loop?
Mostrar comentarios más antiguos
I'm trying to solve a differential equation using the Symbolic Math Toolbox, varying both the equation and the conditions and putting the solutions as elements of a matrix.
This is the code I have:
syms f(x)
DE = zeros(1,5);
for n=1:5
DE(n) = dsolve((2+x.^3)*diff(f,2) - x*diff(f) + n*f, f(-1) == (-1)^n, f(1) == 1);
end
When I try to run this, I get this error:
The following error occurred converting from sym to double:
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use VPA.
Where have I gone wrong?
Respuestas (1)
Torsten
el 10 de Mzo. de 2016
Maybe
syms f(x)
for n=1:5
DE{n} = dsolve((2+x.^3)*diff(f,2) - x*diff(f) + n*f, f(-1) == (-1)^n, f(1) == 1);
end
?
Best wishes
Torsten.
Categorías
Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!