Professional Documents
Culture Documents
1.
(a) The heat equation is
2
2 =0
2 2
( 2 + 2) = 0
2
2
be written as
2
2 =0
As both sides depend on different variables, we can assume the expression above can only be
equal to a constant arbitrarily called 2 .
1
=
= 2
= 2
1
= 2
= 2
= 2
ln() ln() = 2
ln ( ) = 2
()
2
=
2
() =
Now, solving the second equation, we have
+ 2 = 0
We know the solution for this sort of ODEs is a sum of sines and cosines
() = 1 cos() + 2 sin()
Now, lets apply the boundary conditions to find 1 and 2 .
(0, ) = (0) + (0, ) = 1
(, ) = () + (, ) = 0
But it has been defined that (0) = 1 and () = 0 so
(0, ) = 1 + (0, ) = 1
(, ) = 0 + (, ) = 0
Then (0, ) = (, ) = 0. Know, we can use the solution for (, ) and find the constants.
(0, ) = (0) () = 0
(, ) = () () = 0
As we dont want the trivial solution (() = 0), (0) = () = 0. Applying this results in the
solution found for ().
(0) = 1 cos(0) + 2 sin(0) = 0
1 1 + 2 0 = 0
1 = 0
() = 0 cos() + 2 sin() = 0
2 sin() = 0
If both 1 and 2 are zero, we have a trivial solution. So, to avoid it, sin() = 0
= ,
() = 2 sin( )
Now we can rewrite the solution for (, ) (using only one coefficient called ) as
2
(, ) = sin( )
And the solution for each and will be the summation of all the from = 1 to infinity,
because when = 0, 0 = 0
Now, its possible to find () because we assumed
2
2
function. If the second derivative of a function is zero, the first derivative is a constant and the
function itself is given by
() = 1 + 2
Applying the boundary conditions
(0) = 1 0 + 2 = 1
2 = 1
() = 1 + 1 = 0
1 + 1 = 0
1 =
1
() = + 1
Now we have both functions that makes up the solution, we can write it as
2
(, ) = + 1 + sin( )
=1
2
(, 0) + 1 = 0 sin( )
=1
=1
0
0
=1
To simplify the expression above we can take summation out of the integral (because the integral
of sum is the sum of the integrals) and so , because it is a constant for each .
0
0
=1
We also know that the integral of a product of two sine functions only returns a non-zero result
when the argument of both functions are the same, therefore = and the result is 2.
( + 1) sin( ) =
2
0
=1
= ( + 1) sin( )
0
And that is a general solution that can be applied for any initial condition. As we know that the
= (sin ( ) + 1) sin( )
0
= [ sin ( ) sin (
) + sin (
) sin (
) ]
0
0
The solution for the first term will only be non-zero when the arguments are the same, therefore,
sin (
)
0
= ,
=
= sin (
) ,
=
(
)
sin (
) =
cos (
) +
cos (
)
0
0
sin (
) =
cos (
) +
( sin (
))
0
0
2
sin (
) =
cos( )
The solution for the third and last integral is get using a simple substitution of variables
(0) = 0, () =
sin (
sin()
0
(cos() cos(0))
sin (
) =
(1 cos())
sin (
) =
1 = [ + ( cos(1 )) ( (1 cos(1)))]
2 1
1
2
1 = [ ( (2))]
2
2
1 1 2
1 = [ ( )]
2
6
1 = 1
For every 1
2 1 2
= [ ( cos( )) ( (1 cos()))]
= [ cos() ( (1 cos()))]
, = [ (1) ( (1 (1)))]
2
, = [
]
2
3
, = [ ]
6
, =
, = [ (1) ( (1 1))]
2
, = [ ]
2
, =
2
2 =0
2 2
( 2 + 2) = 0
Assuming that
2
2
=0
2
2 =0
We also assume the same solution (, ) = ()() so when applied in the equation above we
have the same ODEs as before which solutions are
() = 1 cos() + 2 sin()
2
() =
Applying the first boundary condition
(0, ) = (0) + (0)() = 1
1 + (0)() = 1
Again, to avoid the trivial solution, (0) = 0 then
() = 2 sin()
Applying the second boundary condition
(, ) = () + ()()
(, ) = () + ()() = 0
To apply the boundary condition, lets assume () = 0, so () = 0 to avoid the trivial solution
then
() = 2 cos()
= 2 cos() = 0
()
Once again to avoid the trivial solution, lets assume the cosine as zero. We know that a cosine is
zero when the argument is an odd number times . This can be written as
=
2
=
, = 1, 3, 5,
2
() = 2 sin (
)
2
Now we need to find (). As its second derivative is zero the first derivative should be a
constant.
But, as we assumed
()
= 0, then
()
(, ) = 1 + sin( )
1
To calculate we need to apply the initial condition, which is (, 0) = 0. We need to take the
same steps as in (a) to solve for
2
0 = 1 + 0 sin (
)
2
1 sin (
) = 1
2
sin (
) sin (
) = 1 sin (
)
2
2
2
1
sin (
) sin (
) = 1 sin (
)
2
2
2
sin (
) sin (
) = sin (
)
2
2
2
= sin (
)
2
2
0
2l
= ( cos (
))
2
n
2 0
1
4
=
[cos ( ) cos(0)]
2
4
=
(, ) = 1
1
Where =
and = 1, 3, 5,
4 2
sin( )
2. To solve this problem numerically, we need to divide the rod of length in divisions. Now we
solve the heat equation for
2
2 =0
2
= 2
= 2 [1 21 + +1 ]
Now we can approximate the temperature of the point of the rod at the point in time
applying Eulers explicit method
+1 = +
Where
]
[ 2 + +1
2 1
is the Courant or CFL number, which we will call . The equation can be simplified to
+1 = 1
+ (1 2) + +1
However, due to the second initial condition is (, ) = 0, we dont have any information about
the value of the temperature at = except that its derivative is zero.
We can argument that if so, the temperature at that point doesnt change in respect to length
only, so we can calculate the temperature of the point before ( 1) that the temperature of the
last point will be the same.
This can be proven using the backwards difference to calculate the derivative for the point,
where =
1
(, ) =
=0
= 1
Now we can apply this result to find the temperature of the second to last point
+1
1
= 2
+ (1 2)1
+
= 1
+1
1 = 2 + (1 2)1
+ 1
+1
1
= 2
+ (1 )1
The temperature of the last point will be the same as the one calculated above as proven before.
We can calculate the temperature for all the points at the ( + 1) instant using the following
vector equation
+1 =
1
1
0
0
0
1 2
0
0
1 2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1 2
0
0
0
0
0
0
0
0
0
0
1
Notice that the product between the two matrices doesnt change the value for 1 at any time.
Also the only other different expression is the one to calculate 1 which was shown before.
The values for (where = ) should be calculated manually equaling it to 1 which was also
shown before.
The attached MATLAB code implementing operations to calculate the temperature at each point
of a bar with = 1 and = 1 at = 0.02 using the conditions given in the problem 1.b. In the
code, the true analytical solution is also calculated for a spatial grid of size 50 and 6 harmonics,
which are enough to produce a smooth curve using the equation derived in 1.b.
Before calculating the solution for this problem, it is needed to define the spatial grid size () and
the time step () which will define the Courant number ().Through trial and error, it can be
seen that the maximum that produces a reliable approximation cannot be bigger than 0.5. So it
has been tested values of and which = 0.5 as shown in the next table.
1
20
0.00125
2
25
3
30
4
35
0.0008
0.0005554
0.0004082
The table above starts with 20 spatial divisions just so we have enough points to plot a curve.
Notice that even though all cases have the same Courant number, the time step used to get it
increases quicker than the spatial grid size. This happens because the Courant number varies with
1
the inverse of the square of ( 2 ). The graphics for each case are attached
to this document.
Analysing the curves, we can see that the three first cases produce results close to the correct
solution, but only the case 4 almost overlap it. And it uses only 49 time steps to do so, which is
about 3 times the amount of time steps in case 1. Notice that it was used the largest time step
possible for each case, so we can still get reliable results using the least amount of processing
power possible. Even a simple PDE as the one in this problem may require a long time to calculate
the solution after a long time and for a big spatial grid size.
So the solution chosen for this problem is the case 4, using 35 spatial divisions and a time
step = 4.082 104 because it produces a close solution to the analytical one for a low cost.
Notice that for a small time as = 0.02 it is needed a more precise time step to get a reliable solution.
The analytical solution requires infinite amount of harmonics to produce an exact solution. For this
example, using 1, 2 or 3 harmonics do not produces reliable enough. For 5 harmonics or more the
difference in the graphic is almost imperceptible.
Analyzing the behavior of the temperature, as is small and all the points starts at = 0 except for the
first point, the rod is still warming up, and so the heat is not well distributed along it. After some seconds
the temperature of the bar will be at the same temperature = 1, which is the value of () calculated
in 1.b, because the exponential factor of the solution will render the (, ) part closer to zero in the
expression for (, ) as the time increases.
Finally, it can be seen that the approximation for a differential equation is harder to do where there is
more variation. This effect is further amplified in a PDE because the time step has time to be managed to
get a steady-state. However, for points where there is no variation this method approximates well, which
can be seen as the numerical solution overlaps the analytical solution after = 0.6 .
Attachments
Plots for the question 2
% Creating a vector (true) with the true results and getting the amount of
% harmonics (H). The size (a) of the solution vector is just an amount big
% enough to produce a smooth curve in the graphic. Another vector xx
a = 50;
true = zeros(a, 1);
xx = linspace(0, 1, a+1);
H = 6;
% Calculating the true results
% First: each point is assigned with the value of 1
% Second: the current harmonic (h) is calculated and ranges from 1 to the
% H-th odd natural number
% Third: lambda is calculated
% Fourth: With the variables calculated above, the true result for the i-th
% point is accumulated H times in the vector element true(i)
for i = 1:a+1
true(i) = 1;
for j = 1:H
h = 2*j-1;
lambda = h*pi/(2*l);
true(i) = true(i) + (-4/(h*pi))*(exp(-k*lambda^2*t))*(sin(lambda*((i1)*l/a))) ;
end
end
% Plotting the numerical and true result in the same plot
hold on;
plot(x,y,'k',xx,true,'r');
legend('Numerical Solution','Analytical Solution');
xlabel('length (m)'); ylabel('Temperature');