-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputo.m
More file actions
40 lines (32 loc) · 732 Bytes
/
computo.m
File metadata and controls
40 lines (32 loc) · 732 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
36
37
38
39
40
n = 20;
m = 200;
xf = 1;
tf = 0.25;
dx = xf / (n - 1)
dt = tf / (m - 1)
cell = zeros(n,m);
% valores iniciales (el ultimo se fuerza por error numerico de sin(pi)
for i=1:n
cell(i,1) = 100 * sin(pi * (i-1) * dx);
end
cell(n,1) = 0;
dx2 = dx^2
r = dt/dx2
alpha = 1
% computo
for j = 2:m
for i = 1:n
if (i == 1)
%cell(i,j) = cell(i,j-1) + alpha * dt * ((cell(i+1,j-1) - cell(i,j-1))/dx2);
cell(i,j) = 0;
elseif (i == n)
cell(i,j) = 0;
%cell(i,j) = cell(i,j-1) + alpha * dt * ((cell(i-1,j-1) - cell(i,j-1))/dx2);
else
cell(i,j) = cell(i,j-1) + alpha * dt * ((cell(i+1,j-1) - 2 * cell(i,j-1) + cell(i-1,j-1))/dx2);
end
end
end
%cell
figure
mesh(cell)