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 个)
Torsten
2016-3-10
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!