67% found this document useful (3 votes)
1K views4 pages

Simple SCILAB CODE For Heat Equation

This SciLab code solves the one-dimensional heat equation for a rod with length L=1 and thermal conductivity k=1. The initial temperature distribution is given by the function f(x)=4x(1-x/L). The code uses finite differences to calculate the temperature u(x,t) at points x from 0 to L over time steps t from 0 to 0.25. It outputs a 3D plot of temperature over space and time and calculates the temperature at the point x=0.4, t=0.2.

Uploaded by

Jason West
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
1K views4 pages

Simple SCILAB CODE For Heat Equation

This SciLab code solves the one-dimensional heat equation for a rod with length L=1 and thermal conductivity k=1. The initial temperature distribution is given by the function f(x)=4x(1-x/L). The code uses finite differences to calculate the temperature u(x,t) at points x from 0 to L over time steps t from 0 to 0.25. It outputs a 3D plot of temperature over space and time and calculates the temperature at the point x=0.4, t=0.2.

Uploaded by

Jason West
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Simple SCILAB CODE for Heat Equation

Que: Write the SciLab code for the solution of one dimensional heat equation
subjected to u(0,t)=u(L,t)=0, if the initial conditions are given by
u(x,0)=f(x)=4*(x/L)*(1-x/L). Use the values of k=1, L=1. Also find the
temperature in rod at x=0.4,t=0.2

Source code:

clc
clear
L=input('Enter the length of rod L')
k=input('Enter the value of coefficient k')
n=input('Enter the number of terms in solution you
want n')
function w=f(x)
w=4*x/L*(1-x/L)
endfunction
for i=1:n
function w1=f1(x)
w1=f(x)*sin(i*%pi*x/L);
endfunction
b(i)=(2/L)*integrate('f1(x)','x',0,L);
end
// calculate u
function uu=u(x, t)
uu=0;
for j=1:n;
uu=uu+b(j)*sin(j*%pi*x/L)*exp(-j^2*
%pi^2*k*t/L^2);
end
endfunction;
x=[0:0.05:1];t=[0:0.025:0.25];
u1=feval(x,t,u);
plot3d(x,t,u1,'x@t@u(x,t)')
//..... for 2d plot.......................
scf(1)
plot(x',u1(:,1),'m.*',x', u1(:,3),'g.-',x',u1(:,6),'b.
+',x',u1(:,9),'r.x')
//u1(:,1) temperature for time t=0,
//u1(:,3) temperature for time t=0.05,
//u1(:,6) temperature for time t=0.075,
//u1(:,9) displacemnt for time t=0.15,
xtitle('Heat equation Solution','x','u(x,t)')

Console Command:
Enter the length of rod L
1
Enter the length of rod L
--> 1

Enter the value of coefficient k


--> 1
Enter the value of coefficient k
1

Enter the number of terms in solution you want n


30
Enter the number of terms in solution you want n
--> 30

Plot 2D:
Plot 3D:
Numerical output:
u1=feval(.4,.2,u)
u1 =
0.1363464

You might also like