File:Numerical integration illustration, h=0.25.png
Da testwiki.
Vai alla navigazione
Vai alla ricerca
Dimensioni di questa anteprima: 412 × 600 pixel. Altre risoluzioni: 165 × 240 pixel | 330 × 480 pixel | 528 × 768 pixel | 703 × 1 024 pixel | 1 500 × 2 183 pixel.
File originale (1 500 × 2 183 pixel, dimensione del file: 85 KB, tipo MIME: image/png)
Questo file proviene da Wikimedia Commons e può essere utilizzato da altri progetti. Di seguito viene mostrata la descrizione presente nella pagina di descrizione del file.
Dettagli
Licenza
| Public domainPublic domainfalsefalse |
| Io, detentore del copyright su quest'opera, la rilascio nel pubblico dominio. Questa norma si applica in tutto il mondo. In alcuni paesi questo potrebbe non essere legalmente possibile. In tal caso: Garantisco a chiunque il diritto di utilizzare quest'opera per qualsiasi scopo, senza alcuna condizione, a meno che tali condizioni siano richieste dalla legge. |
Source code (MATLAB)
% illustration of numerical integration
% compare the Forward Euler method, which is globally O(h)
% with Midpoint method, which is globally O(h^2)
% and the exact solution
function main()
f = inline ('y', 't', 'y'); % will solve y' = f(t, y)
a=0; b=4; % endpoints of the interval where we will solve the ODE
N = 17; T = linspace(a, b, N); h = T(2)-T(1); % the grid
y0 = 1; % initial condition
% solve the ODE
Y_euler = solve_ODE (N, f, y0, h, T, 1); % Forward Euler method
Y_midpt = solve_ODE (N, f, y0, h, T, 2); % midpoint method
T_highres = a:0.1:b; Y_exact = exp(T_highres);
% prepare the plotting window
lw = 3; % curves linewidth
fs = 20; % font size
figure(1); clf; set(gca, 'fontsize', fs); hold on;
% colors
red=[0.867 0.06 0.14];
blue = [0, 129, 205]/256;
green = [0, 200, 70]/256;
% plot the solutions
plot(T, Y_euler, 'color', blue, 'linewidth', lw)
plot(T, Y_midpt, 'color', green, 'linewidth', lw)
plot(T_highres, Y_exact, 'color', red, 'linewidth', lw)
% axes aspect ratio
pbaspect([1 1.5 1]);
% save to disk
disp(sprintf('Grid size is %0.9g', h))
saveas(gcf, sprintf('Numerical_integration_illustration,_h=%0.2g.eps', h), 'psc2');
function Y = solve_ODE (N, f, y0, h, T, method)
Y = 0*T;
Y(1)=y0;
for i=1:(N-1)
t = T(i); y = Y(i);
if method == 1 % forward Euler method
Y(i+1) = y + h*f(t, y);
elseif method == 2 % explicit one step midpoint method
K = y + 0.5*h*f(t, y);
Y(i+1) = y + h*f(t+h/2, K);
else
disp ('Don`t know this type of method');
return;
end
end
Didascalie
Aggiungi una brevissima spiegazione di ciò che questo file rappresenta
Elementi ritratti in questo file
raffigura
Valore sconosciuto senza un elemento Wikidata
Cronologia del file
Fare clic su un gruppo data/ora per vedere il file come si presentava nel momento indicato.
| Data/Ora | Miniatura | Dimensioni | Utente | Commento | |
|---|---|---|---|---|---|
| attuale | 04:02, 25 mag 2007 | 1 500 × 2 183 (85 KB) | wikimediacommons>Oleg Alexandrov | Make exact solution smooth |
Utilizzo del file
La seguente pagina usa questo file: