Advertisement
makispaiktis

Efarmosmena2_Course2

Oct 16th, 2020 (edited)
1,945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.65 KB | None | 0 0
  1. clear all
  2.  
  3. I = 300;    % xronos
  4. N = 100;    % xwros
  5.  
  6. dt = 0.005;
  7. L = 1;
  8. dx = L / N;
  9.  
  10. c = 0.1;
  11.  
  12. for n = 1:N+1
  13.     u(1,n) = f((n-1)*dx);
  14. end
  15.  
  16. for i = 2:I
  17.     t = i*dt;
  18.     u(i,1) = g1(t);
  19.     for n = 2:N
  20.         % x = n * dx
  21.         u(1,n) = u(i-1,n) + dt*c^2*(u(i-1,n-1) - 2*u(i-1,n) + u(i-1, n+1)) / (dx^2);
  22.     end
  23.     u(i,N+1) = g2(t);
  24. end
  25.  
  26.  
  27. figure(1);
  28. s = surf(u);
  29. axis([0 N 0 I -0.1 1.1]);
  30. s.EdgeColor = 'none';
  31.  
  32.  
  33. function F = f(x)
  34.     if 0.25<x && x<0.75
  35.         F = 1;
  36.     else
  37.         F = 0;
  38.     end
  39. end
  40.  
  41. function G = g1(t)
  42.     G = 0; % abs(cos(5*t));
  43. end
  44.  
  45. function G = g2(t)
  46.     G = 1; % abs(sin(10*t));
  47. end
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement