Advertisement
Guest User

sddas

a guest
Oct 22nd, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. %% Ecuacion de onda
  2.  
  3. % u_tt = c^2 u_xx 0<x<L 0<t<T
  4. % Condiciones de contorno
  5. % u(0,t) = l(t) u(L,t) = r(t)
  6. %
  7. % Condiciones iniciales
  8. % u(x,0) = f(x), u_t(x,0) = g(x)
  9. %
  10. %% Datos
  11. c=1;L=4;T=4;
  12. nx=4;nt=8; %%m=nt
  13. % Condiciones
  14. f = @(x) 2-abs(x-2)
  15. g = @(x) zeros(size(x))
  16. l = @(t) zeros(size(t))
  17. r = @(t) zeros(size(t))
  18.  
  19. %% Discretizar
  20. h = L/nx;
  21. k = T/nt;
  22. alfa = c^2*k^2/h^2;
  23. x = 0:h:L;
  24. t = 0:k:T;
  25. u = zeros(nx+1,nt+1);
  26.  
  27. %% Condiciones i y c
  28. u(:,1) = f(x);
  29. u(1,:) = l(t);
  30. u(nx+1,:) =r(t);
  31.  
  32. %% Método explícito
  33. I = 2:nx;
  34. u(I,2) = alfa*(f(x(I-1))+f(x(I+1)))+(1-alfa)*f(x(I))+k*g(x(I))
  35. %%
  36. for j=2:nt
  37. u(I,j+1) = alfa*(u(I+1,j)+u(I+1,j))+2*(1+alfa)*u(I,j)-u(I,j-1)
  38. pause
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement