DIR Return Create A Forum - Home
---------------------------------------------------------
Telelocos
HTML https://telelocos.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: Dudas sobre Matlab
*****************************************************
#Post#: 73--------------------------------------------------
problema 2
DIR By: antay
Date: January 9, 2014, 7:24 am
---------------------------------------------------------
a = 0; L = 2; % Intervalo de x
h = 0.1; % Paso de x
x = (a:h:L)'; % En columna
t0 = 0; tf = 2; % Un tiempo final arbitrario
k = 0.5; t = t0:k:tf,pause
nx = length(x); nt = length(t);
c = 10^(-2)
gamma = c*k/h^2;
u = zeros(nx,nt);
u(:,1) = sin(pi*x); % u(x,0) = g(x)
u(1,:) = zeros(size(t)); % u(0,t) = f0(t)
u(end,:) = zeros(size(t)); % u(L,t) = fL(t)
plot(x,u(:,1)); % Temperatura en el tiempo inicial
v1 = (1+2*gamma)*ones(nx-2,1);
v2 = -gamma*ones(nx-3,1);
A = diag(v1)+diag(v2,1)+diag(v2,-1);%introducimos v1 y v2 en las
respectivas diagonales
%A
for j=2:nt
b = u(2:end-1,j-1);
b(1)=b(1)+gamma*u(1,j);
b(end)=b(end)+gamma*u(end,j);
u(2:end-1,j) = A\b;
%b,pause
end
u
plot(x,u)
ta=tf; %CAMBIAR SEGUN EL VALOR DE t elegir la columna asociada
uex = sin(pi*x)*exp(-c*pi^2*ta);
compara = [uex u(:,end)]
error= abs(compara(:,1)-compara(:,2));
emax=max(error)
emedio=sum(error)/nx
*****************************************************
Page 1 of 1