I can't take several non-linear inputs and assign them names for using later in the code.
조회 수: 1 (최근 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).
댓글 수: 0
채택된 답변
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
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' '; '
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!