Adding a plot to my code
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ollie
am 15 Aug. 2015
Kommentiert: Star Strider
am 16 Aug. 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 Kommentare
Akzeptierte Antwort
Star Strider
am 15 Aug. 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 Kommentare
Star Strider
am 16 Aug. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Function Creation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!