Get dsolve to accept an inputted string?
显示 更早的评论
I am trying to solve an ODE (like dy/dx = 3*exp(-x)-0.4*y), but, it seems that matlab doesn't like me using a sym that was converted from a string. If i replace == equation in line 4 with == 3*exp(-x)-0.4*y (which is what I inputted), then this works. However, I need to accept an inputted equation. So how could I get dsolve to work with a string?
% This works
placeholder = input('Enter ODE -> ','s');
equation = str2sym(placeholder)
syms y(x);
true_equation = diff(y,x) == 3*exp(-x)-(2/5)*y % <-- what I want to change
condition = y(Xo) == Yo
true_equation = dsolve(true_equation,condition)
% This doesn't
placeholder = input('Enter ODE -> ','s');
equation = str2sym(placeholder)
syms y(x);
true_equation = diff(y,x) == equation
condition = y(Xo) == Yo
true_equation = dsolve(true_equation,condition)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!