Printing cell array elements
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 ');
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?
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Online Estimation 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!