Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Ecuacion de onda
- % u_tt = c^2 u_xx 0<x<L 0<t<T
- % Condiciones de contorno
- % u(0,t) = l(t) u(L,t) = r(t)
- %
- % Condiciones iniciales
- % u(x,0) = f(x), u_t(x,0) = g(x)
- %
- %% Datos
- c=1;L=4;T=4;
- nx=4;nt=8; %%m=nt
- % Condiciones
- f = @(x) 2-abs(x-2)
- g = @(x) zeros(size(x))
- l = @(t) zeros(size(t))
- r = @(t) zeros(size(t))
- %% Discretizar
- h = L/nx;
- k = T/nt;
- alfa = c^2*k^2/h^2;
- x = 0:h:L;
- t = 0:k:T;
- u = zeros(nx+1,nt+1);
- %% Condiciones i y c
- u(:,1) = f(x);
- u(1,:) = l(t);
- u(nx+1,:) =r(t);
- %% Método explícito
- I = 2:nx;
- u(I,2) = alfa*(f(x(I-1))+f(x(I+1)))+(1-alfa)*f(x(I))+k*g(x(I))
- %%
- for j=2:nt
- u(I,j+1) = alfa*(u(I+1,j)+u(I+1,j))+2*(1+alfa)*u(I,j)-u(I,j-1)
- pause
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement