필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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).

채택된 답변

Matt J
Matt J 2014년 11월 5일
편집: Matt J 2014년 11월 5일
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
Matt J
Matt J 2014년 11월 6일
편집: Matt J 2014년 11월 6일
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 2014년 11월 6일
I am grateful to you for your great help Matt J. I appreciate your assistance every step of the way. Thank you very much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by