How to request input and set as symbols?

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by