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!