How do I use dsolve within a for loop?
Show older comments
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?
Answers (1)
Torsten
on 10 Mar 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.
Categories
Find more on Symbolic Math Toolbox 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!