Borrar filtros
Borrar filtros

How to request input and set as symbols?

2 visualizaciones (últimos 30 días)
David Hagan
David Hagan el 10 de Feb. de 2012
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Feb. de 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.

Más respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by