|
I need help to run this code in a M file, Is there any body who has an idea why this code is not runing
%
% Main program for the numerical integration of
% the PDE modeling heat conduction in a solid slab.
%
global n length;
%
% set the initial conditions
%
n = 51; % Number of grid points (including boundaries)
length = 1; % Length of the slab
dx =length/(n-1);
%
% Initial conditions definition
%
for i = 1:n,
x (i) = (i-1)*dx;
tic (i) = 100*sin(pi*x(i)/length);
end
tspan = linspace(0,1);
%
% Integration of the discretized PDE system
%
[time,temp] = ode15s('fcn',tspan,tic);
[lastp,nn] = size(time);
plot(temp(1,1:n)),hold,xlabel('x'),ylabel('T')
for i = 2:lastp,
plot(temp(i,1:n))
end
function fx = fcn (time,t)
global n length
%
% left boundary condition
%
t (1) = 0;
%
% right boundary condition
%
t (n) = 0;
%
% first-order derivative tx
%
tx = dss002 (0,length,n,t);
%
% second order derivative txx
%
txx = dss002 (0,length,n,tx);
%
% return the discretized value of the second order derivative
%
fx = txx';
end
function ux = dss002 (xl,xu,n;u)
%
% Function dss002 computes the first derivative, "ux", of a
% variable "u" over the spatial domain xl .le. x .le. xu from
% the classical three point, second order finite difference approximations.
%
% Inputs:
% -------
% xl = lower boundary value of x
% xu = upper boundary value of x
% n = number of grid points in the x domain
% including the boundary points
% u = one dimensional array containing the value of u at
% the n grid points for which the derivative is to be computed
%
% Outputs:
% -------
% ux = one dimensional array containing the numerical values of
% the derivatives of u at the n grid points
%
% Matlab version written by: Antonio Flores T./ April 2002
%
%
% Spatial increment
%
dx = (xu-xl)/(n-1);
r2fdx = 1/(2*dx);
nm1 = n-1;
%
% Equation (12)
%
ux (1) = r2fdx*(-3*u(1)+4*u(2)-u(3));
%
% Equation (9)
%
for i = 2:nm1,
ux (i) = r2fdx*(-u(i-1)+u(i+1));
end
%
% Equation (13)
%
ux (n) = r2fdx*(u(n-2)-4*u(n-1)+3*u(n));
%-- End of the dss002.m file --
end
|