Printing cell array elements

조회 수: 2 (최근 30일)
Ali Kiral
Ali Kiral 2022년 11월 6일
편집: VBBV 2022년 11월 6일
Below script is an application of Newton's method to solve a set of nonlinear equations. Here we have 3 equations in 3 unknowns. All things starting with f is a function m-file. The script generates a cell array x having 9 3x1 arrays. These 3x1 arrays are estimates of three unknowns. I want to print the triple of estimates for each iteration (every time while loop runs)
a=input('Enter the guess for the first variable ');
Unable to run the 'fevalJSON' function because it calls the 'input' function, which is not supported for this product offering.
b=input('Enter the guess for the second variable ');
c=input('Enter the guess for the third variable ');
k=input('Enter the accuracy ');
x{1}=[a;b;c]; i=1;
F=[f1(a, b ,c); f2(a, b ,c); f3(a, b ,c)];
while max(abs(F))>=10^-k
J=[f1x1(a, b ,c) f1x2(a, b ,c) f1x3(a, b ,c);f2x1(a, b ,c) f2x2(a, b ,c) f2x3(a, b ,c);f3x1(a, b ,c) f3x2(a, b ,c) f3x3(a, b ,c)];
F=[f1(a, b ,c); f2(a, b ,c); f3(a, b ,c)];
y=J\-F;
x{i+1}=x{i}+y;
R=[x{i+1}(1);x{i+1}(2);x{i+1}(3)];
fprintf(' the root estimates xr=[x1;x2;...;xn] are: \n', R)
a=x{i+1}(1);
b=x{i+1}(2);
c=x{i+1}(3);
F=[f1(a, b ,c); f2(a, b ,c); f3(a, b ,c)];
i=i+1;
end
MATLAB does not show R, only prints 'the root estimates..' Why does it do so? Is there a problem with the formation of R?

채택된 답변

VBBV
VBBV 2022년 11월 6일
편집: VBBV 2022년 11월 6일
fprintf(' the root estimates xr=[x1;x2;...;xn] are: \n%f', R)
Missing format specifier

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by