Adding a plot to my code
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ollie
el 15 de Ag. de 2015
Comentada: Star Strider
el 16 de Ag. de 2015
I've attached my code which performs the Jacobi method and is working correctly. However, I need to calculate the residual, rk which is the infinity norm of (Ax(k) - b ) divided by the infinity norm of b. What I need to do is calculate the natural log of rk and plot it against the iteration number K. I then need to be able to access the values on the y-axis.
I believe the code I need is
rk = (norm(A*x - b, inf)) / (norm(b,inf));
plot(log(rk),K);
but I have no idea how to incorporate this into my existing code or how to access the y-axis values. Is there anyone who could return the code to me with plotting commands? Thanks
0 comentarios
Respuesta aceptada
Star Strider
el 15 de Ag. de 2015
I can’t run your code because I’m not certain what the arguments are.
However, I would make these changes in the loop, then put the plot call after the end of the ‘K’ loop:
X(:,1) = x0;
rk(K) = norm(x-xtemp,inf)/norm(xtemp,inf);
if rk(K)<tol
break;
end
K = 1:length(rk);
figure(1)
plot(log(rk),K)
The ‘X(:,1)’ assignment is unchanged. I just put it in to show where I would put the ‘rk’ assignment.
NOTE: This is untested code. You may have to experiment with it to get the result you want.
4 comentarios
Star Strider
el 16 de Ag. de 2015
My pleasure!
The problem may be that they exist only in the function workspace, not your script workspace. (A function’s workspace is local only to it.) You may have to return them from the function to your script workspace to access them.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!