How do I use dsolve within a for loop?

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?

回答(1 个)

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.

类别

在 帮助中心 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

提问:

2016-3-10

回答:

2016-3-10

Community Treasure Hunt

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

Start Hunting!

Translated by