Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- I = 300; % xronos
- N = 100; % xwros
- dt = 0.005;
- L = 1;
- dx = L / N;
- c = 0.1;
- for n = 1:N+1
- u(1,n) = f((n-1)*dx);
- end
- for i = 2:I
- t = i*dt;
- u(i,1) = g1(t);
- for n = 2:N
- % x = n * dx
- 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);
- end
- u(i,N+1) = g2(t);
- end
- figure(1);
- s = surf(u);
- axis([0 N 0 I -0.1 1.1]);
- s.EdgeColor = 'none';
- function F = f(x)
- if 0.25<x && x<0.75
- F = 1;
- else
- F = 0;
- end
- end
- function G = g1(t)
- G = 0; % abs(cos(5*t));
- end
- function G = g2(t)
- G = 1; % abs(sin(10*t));
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement