フィルターのクリア

How to request input and set as symbols?

2 ビュー (過去 30 日間)
David Hagan
David Hagan 2012 年 2 月 10 日
I am attempting to write a code for the Newton-Raphson method which essentially solves a system of n equations and n unknowns. I am trying to ask for user input (in the form of equations, initial values, etc.). As far as I know, I have to set the variables to symbols.
How can I request the user input for the variables to be used before asking for the equations?
in = 1;
data = [];
i = 1;
while in ~= 0
var_string(i) = input('What variables are you using? End with "end" ','s');
if var_string(i) == 'end'
break;
else
variable(i) = sym(var_string(i))
i = i + 1;
end
end
This is what I have at this point. Is there a way to do this? Thanks.

採用された回答

Walter Roberson
Walter Roberson 2012 年 2 月 10 日
input() is going to return a string, not a cell array. Unless the string happens to be only a single character long, it is not going to fit in to var_string(i) . Switch to cell arrays for var_string .
Also, do not use == to compare strings. For example,
'hi' == 'end'
is going to give you an error about inconsistent dimensions. Use one of the string comparison functions.

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by