-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmieuler.m
More file actions
35 lines (28 loc) · 924 Bytes
/
Copy pathmieuler.m
File metadata and controls
35 lines (28 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function [t,u] = mieuler(t0, tfin, N, x0, f, par)
% MÉTODO DE EULER - orden 1
%
% DATOS DE ENTRADA
% t0 tiempo inicial
% tfin tiempo final T
% N numero de pasos
% x0 valor inicial, vector columna
% f(t,x) funcion de la E.D.O.
% p puede ser una variable de entrada con parametros,se incorpora al final de los
% datos de entrada, y si no los hay se define como una variable vacia par = []
%
% DATOS DE SALIDA
% t vector fila de tiempos t(n)
% u tabla de valores de x(t(n))
dim = size(x0,1);
%definir el paso h;
h= (tfin-t0)/N;
%generar t, el mallado de puntos donde vamos a calcular la aproximación
t= t0:h:tfin; % Eq a linspace(t0,tfin,N+1)
%inicializar la variable u como una tabla de ceros (la columna n+1 representa
%la aproximación de x(tn)), añadiendo el valor inicial
u = [x0, zeros(dim,N)];
% Iteramos N veces
for i=1:N
u(:,i+1) = u(:,i) + h*f(t(i),u(:,i),par);
end
end