Trouble with graph in loop
Mostra commenti meno recenti
The problem is simple, I'm trying to graph the Global Error of Euler's method vs. the step size 'h' but I cannot end up with a line, only points are graphed.
Let 'm' be a natural number such as m=2,4,6...100. The step size h is 1/m.
We want to draw a graph with GLOBAL ERROR vs h depending on m.
%Experiment
%u'=1/(1+t)^2 u(0)=0 en el intervalo [0,1]
exact=0.5; %exact value
f=@(t,u) 1./(1+t).^2;
t0=0;
tfinal=1;
u0=0;
for m=2:2:100
hold on
h=1./m; %step (variable)
[vt,vsol]=ode1(t0,h,tfinal,f,u0); %ode1 is Euler's method solver
approx=vsol(end);
errorglobal = approx - exact;
loglog(errorglobal, h, '-o')
set(gca, 'XScale', 'log', 'YScale', 'log');
grid on
hold off
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
