Is it wrong to use eval() to read input function?

12 ビュー (過去 30 日間)
Sergio Luis López Verbel
Sergio Luis López Verbel 2020 年 9 月 8 日
I want to have a program that prompts the users for an equation and solves it with solve().
syms vrb
vname = input('Input variable name: ','s');
str = input('Equation: ','s');
eqn = eval(str);
solu = solve(eqn,vrb);
fprintf('%s is equal to %d.\n',vname,solu)
I also want to expand the program to solving multivariate equations but I feel that the use of eval() might complicate its efficiency to begin with.

採用された回答

madhan ravi
madhan ravi 2020 年 9 月 8 日
eqn = str2sym(str)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by