I can't take several non-linear inputs and assign them names for using later in the code.

1 visualizzazione (ultimi 30 giorni)
I am trying to do the following operation:
a=input('Enter the no. of equations');
counter=1;
while counter<=a
f_counter=input('enter the equation','s');
F(counter)=f_counter;
counter=counter+1;
end
F is a row vector ,supposed to be,changing size and storing the non-linear equations entered by the user. The problem is 'f_counter' is being considered as a single name instead of f_1 , f_2 etc. I am writing a code for Newton's method for non-linear equations(if that helps).

Risposta accettata

Matt J
Matt J il 5 Nov 2014
Modificato: Matt J il 5 Nov 2014
The problem is 'f_counter' is being considered as a single name instead of f_1 , f_2 etc.
Even if 'f_counter' did what you were hoping, it would (a) be bad coding practice and (b) serve no purpose because you are putting the input in F anyway. There's no reason the inputs have to be held in 2 places, as far as I can see. However, F needs to be a cell array as below
a=input('Enter the no. of equations');
counter=1;
while counter<=a
F{counter}=input('enter the equation','s');
counter=counter+1;
end
  7 Commenti
Matt J
Matt J il 6 Nov 2014
Modificato: Matt J il 6 Nov 2014
Well, for a full understanding, you'll probably need to read up on cell array manipulation,
However, you can also gain an understanding of what my commands are doing by running them individually at the command line and displaying their output. For example, below you can see that F(:,2)={'; '} is just adding a column of semicolons to the original F,
>> F={'x+y';'x*y'}, F(:,2)={'; '},
F =
'x+y'
'x*y'
F =
'x+y' '; '
'x*y' '; '
Ahsun Ali
Ahsun Ali il 6 Nov 2014
I am grateful to you for your great help Matt J. I appreciate your assistance every step of the way. Thank you very much.

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by