How to request input and set as symbols?

5 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 10 Feb 2012
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.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!