Adding a plot to my code
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Star Strider
le 15 Août 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 commentaires
Star Strider
le 16 Août 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!