Homework Assignment #8
Student: Vinicius Fontes
ASU # ID: 1208318367
1.
(a) The heat equation is
𝜕𝑇
𝜕𝑡− 𝑘
𝜕2𝑇
𝜕𝑥2= 0
First, let’s assume a solution in the format
𝑇(𝑥, 𝑡) = ψ(x) + 𝜙(𝑥, 𝑡)
And also
ψ(0) = 𝑇(0, 𝑡) = 1
ψ(𝑙) = 𝑇(𝑙, 𝑡) = 0
This solution is chosen because we have a non homogeneous condition for 𝑥 = 0 and 𝑥 = 𝑙. If we
had, 𝜓(𝑥) = 0 and the solution would be the same as a non homogeneous PDE. Nevertheless the
conditions for 𝜙(𝑥, 𝑡) will always be homogeneous using this method. Applying the solution to
the PDE gives
𝜕𝜙
𝜕𝑡− 𝑘 (
𝜕2𝜓
𝜕𝑥2+
𝜕2𝜙
𝜕𝑥2) = 0
Because 𝜓(𝑥) does not depend on 𝑡. Let’s also assume that 𝜕2𝜓
𝜕𝑥2 = 0 so the equation above can
be written as
𝜕𝜙
𝜕𝑡− 𝑘
𝜕2𝜙
𝜕𝑥2= 0
Let’s assume a solution 𝜙(𝑥, 𝑡) = 𝑓(𝑥)𝑔(𝑡) and rearrange the equation as
1
𝑘𝑓𝑔′ = 𝑔𝑓′′
Dividing both sides by 𝑓𝑔 1
𝑘 𝑔′
𝑔=
𝑓′′
𝑓
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
From this argument we have two ODE.
𝑖. 𝑔′ = −𝑘𝜆2𝑔
𝑖𝑖. 𝑓′′ + 𝜆2𝑓 = 0
To solve the first ODE we only need to use separation of variables
𝑔′
𝑔= −𝑘𝜆2
1
𝑔
𝑑𝑔
𝑑𝑡 = −𝑘𝜆2
𝑑𝑔
𝑔= −𝑘𝜆2𝑑𝑡
∫𝑑𝑔∗
𝑔∗
𝑔
𝐴
= ∫−𝑘𝜆2𝑑𝑡∗
𝑡
0
ln(𝑔) − ln(𝐴) = −𝑘𝜆2𝑡
ln (𝑔
𝐴) = −𝑘𝜆2𝑡
𝑔(𝑡)
𝐴= 𝑒−𝑘𝜆2𝑡
𝑔(𝑡) = 𝐴𝑒−𝑘𝜆2𝑡
Now, solving the second equation, we have
𝑓′′ + 𝜆2𝑓 = 0
We know the solution for this sort of ODE’s is a sum of sines and cosines
𝑓(𝑥) = 𝐵1 cos(𝜆𝑥) + 𝐵2 sin(𝜆𝑥)
Now, let’s 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 don’t 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, it’s possible to find 𝜓(𝑥) because we assumed 𝜕2𝜓
𝜕𝑥2 = 0 and we know that it is not a zero
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) = 𝐶10 + 𝐶2 = 1
𝐶2 = 1
𝜓(𝑙) = 𝐶1𝑙 + 1 = 0
𝐶1𝑙 + 1 = 0𝑙
𝐶1 = −1
𝑙
𝜓(𝑥) = −1
𝑙𝑥 + 1
Now we have both functions that makes up the solution, we can write it as
𝑇(𝑥, 𝑡) = −𝑥
𝑙+ 1 + ∑ 𝐶𝑛𝑒
−𝑘𝜆𝑛2 𝑡 sin(𝜆𝑛𝑥)
∞
𝑛=1
Now, let’s apply an arbitrary initial condition 𝑇(𝑥, 0) = 𝑇𝑖
𝑇(𝑥, 0) +𝑥
𝑙− 1 = ∑ 𝐶𝑛𝑒−𝑘𝜆𝑛
20 sin(𝜆𝑛𝑥)
∞
𝑛=1
To solve for 𝐶𝑛, we multiply both sides by sin(𝜆𝑚𝑥)
(𝑇𝑖 +𝑥
𝑙− 1) sin(𝜆𝑚𝑥) = ∑ 𝐶𝑛1 sin(𝜆𝑛𝑥) sin(𝜆𝑚𝑥)
∞
𝑛=1
Now we integrate both sides o the equation in 𝑥 from 0 to 𝑙.
∫ (𝑇𝑖 +𝑥
𝑙− 1) sin(𝜆𝑚𝑥) 𝑑𝑥
𝑙
0
= ∫ ∑ 𝐶𝑛 sin(𝜆𝑛𝑥) sin(𝜆𝑚𝑥)
∞
𝑛=1
𝑑𝑥𝑙
0
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 𝑛.
∫ (𝑇𝑖 +𝑥
𝑙− 1) sin(𝜆𝑚𝑥)𝑑𝑥
𝑙
0
= ∑ 𝐶𝑛 ∫ sin(𝜆𝑛𝑥) sin(𝜆𝑚𝑥)𝑙
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(𝜆𝑛𝑥) 𝑑𝑥
𝑙
0
= ∑𝐶𝑛𝑙
2
∞
𝑛=1
Applying these arguments and solving for 𝐶𝑛 gives us
𝐶𝑛 =2
𝑙∫ (𝑇𝑖 +
𝑥
𝑙− 1) sin(𝜆𝑛𝑥)𝑑𝑥
𝑙
0
And that is a general solution that can be applied for any initial condition. As we know that the
initial condition is 𝑇𝑖 = sin (𝜋𝑥
𝑙), we can find each 𝐶𝑛
𝐶𝑛 =2
𝑙∫ (sin (
𝜋𝑥
𝑙) +
𝑥
𝑙− 1) sin(𝜆𝑛𝑥)𝑑𝑥
𝑙
0
𝐶𝑛 =2
𝑙[∫ sin (
𝜋𝑥
𝑙) sin (
𝑛𝜋𝑥
𝑙)𝑑𝑥
𝑙
0
+1
𝑙∫ 𝑥 sin (
𝑛𝜋𝑥
𝑙)𝑑𝑥
𝑙
0
− ∫ sin (𝑛𝜋𝑥
𝑙) 𝑑𝑥
𝑙
0
]
The solution for the first term will only be non-zero when the arguments are the same, therefore,
for 𝑛 = 1 the solution for the first integral is 𝑙
2.
To get the solution for the second integral we should solve it by parts
∫ 𝑥 sin (𝑛𝜋𝑥
𝑙)𝑑𝑥
𝑙
0
𝑢 = 𝑥, 𝑑𝑢 = 𝑑𝑥
𝑑𝑣 = sin (𝑛𝜋𝑥
𝑙)𝑑𝑥, 𝑣 = −
𝑙
𝑛𝜋𝑐𝑜𝑠 (
𝑛𝜋𝑥
𝑙)
∫ 𝑥 sin (𝑛𝜋𝑥
𝑙)𝑑𝑥
𝑙
0
= −𝑥𝑙
𝑛𝜋cos (
𝑛𝜋𝑥
𝑙)0
𝑙
+𝑙
𝑛𝜋∫cos (
𝑛𝜋𝑥
𝑙)𝑑𝑥
𝑙
0
∫ 𝑥 sin (𝑛𝜋𝑥
𝑙)𝑑𝑥
𝑙
0
= −𝑥𝑙
𝑛𝜋cos (
𝑛𝜋𝑥
𝑙)0
𝑙
+𝑙
𝑛𝜋(
𝑙
𝑛𝜋sin (
𝑛𝜋𝑥
𝑙))
0
𝑙
∫ 𝑥 sin (𝑛𝜋𝑥
𝑙)𝑑𝑥
𝑙
0
=𝑙2
𝑛𝜋cos(𝑛𝜋 )
The solution for the third and last integral is get using a simple substitution of variables
∫ sin(𝑛𝜋𝑥
𝑙) 𝑑𝑥
𝑙
0
𝑢 =𝑛𝜋𝑥
𝑙
𝑑𝑥 = 𝑙𝑑𝑢
𝑛𝜋
𝑢(0) = 0, 𝑢(𝑙) = 𝑛𝜋
𝑙
𝑛𝜋∫ sin(𝑢) 𝑑𝑢
𝑛𝜋
0
∫ sin(𝑛𝜋𝑥
𝑙)𝑑𝑥
𝑙
0
= −𝑙
𝑛𝜋(cos(𝑛𝜋) − cos(0))
∫ sin(𝑛𝜋𝑥
𝑙)𝑑𝑥
𝑙
0
=𝑙
𝑛𝜋(1 − cos(𝑛𝜋))
Using these solution to find 𝐶1
𝐶1 =2
𝑙[𝑙
2+
1
𝑙(
𝑙2
1𝜋cos(1𝜋 )) − (
𝑙
1𝜋(1 − cos(1𝜋)))]
𝐶1 =2
𝑙[𝑙
2−
𝑙
𝜋− (
𝑙
𝜋(2))]
𝐶1 =2
𝑙[𝑙 (
1
2−
1
𝜋−
2
𝜋)]
𝐶1 = 1 −6
𝜋
For every 𝑛 ≠ 1
𝐶𝑛 =2
𝑙[1
𝑙(
𝑙2
𝑛𝜋cos(𝑛𝜋 )) − (
𝑙
𝑛𝜋(1 − cos(𝑛𝜋)))]
𝐶𝑛 =2
𝑙[
𝑙
𝑛𝜋cos(𝑛𝜋) − (
𝑙
𝑛𝜋(1 − cos(𝑛𝜋)))]
For odd 𝑛, cos(𝑛𝜋) = −1
𝐶𝑛,𝑜𝑑𝑑 =2
𝑙[
𝑙
𝑛𝜋(−1) − (
𝑙
𝑛𝜋(1 − (−1)))]
𝐶𝑛,𝑜𝑑𝑑 =2
𝑙[−
𝑙
𝑛𝜋−
2𝑙
𝑛𝜋]
𝐶𝑛,𝑜𝑑𝑑 =2
𝑙[−
3𝑙
𝑛𝜋]
𝐶𝑛,𝑜𝑑𝑑 = −6
𝑛𝜋
For even 𝑛, cos(𝑛𝜋) = 1
𝐶𝑛,𝑒𝑣𝑒𝑛 =2
𝑙[
𝑙
𝑛𝜋(1) − (
𝑙
𝑛𝜋(1 − 1))]
𝐶𝑛,𝑒𝑣𝑒𝑛 =2
𝑙[
𝑙
𝑛𝜋]
𝐶𝑛,𝑒𝑣𝑒𝑛 =2
𝑛𝜋
(b) The heat equation is
𝜕𝑇
𝜕𝑡− 𝑘
𝜕2𝑇
𝜕𝑥2= 0
First, let’s assume a solution in the format
𝑇(𝑥, 𝑡) = ψ(x) + 𝜙(𝑥, 𝑡)
And also
ψ(0) = 𝑇(0, 𝑡) = 1
But this time, we have one more expression
∂T
∂x(𝑙, 𝑡) = 0
Applying the solution to the PDE gives
𝜕𝜙
𝜕𝑡− 𝑘 (
𝜕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 ODE’s as before which solutions are
𝑓(𝑥) = 𝐵1 cos(𝜆𝑥) + 𝐵2sin(𝜆𝑥)
𝑔(𝑡) = 𝐴𝑒−𝑘𝜆2𝑡
Applying the first boundary condition
𝑇(0, 𝑡) = 𝜓(0) + 𝑓(0)𝑔(𝑡) = 1
1 + 𝑓(0)𝑔(𝑡) = 1
Again, to avoid the trivial solution, 𝑓(0) = 0 then
𝑓(𝑥) = 𝐵2sin(𝜆𝑥)
Applying the second boundary condition
𝜕𝑇
𝜕𝑥(𝑥, 𝑡) = 𝜓′(𝑥) + 𝑓′(𝑥)𝑔(𝑡)
𝜕𝑇
𝜕𝑥(𝑙, 𝑡) = 𝜓′(𝑙) + 𝑓′(𝑙)𝑔(𝑡) = 0
To apply the boundary condition, let’s assume 𝜕𝜓
𝜕𝑥(𝑙) = 0, so 𝑓′(𝑙) = 0 to avoid the trivial solution
then
𝑓′(𝑥) = 𝐵2𝜆 cos(𝜆𝑥)
𝑓′(𝑙) = 𝐵2𝜆 cos(𝜆𝑙) = 0
Once again to avoid the trivial solution, let’s 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
𝜆 =𝑛𝜋
2𝑙, 𝑛 = 1, 3, 5, …
𝑓(𝑥) = 𝐵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
𝜕𝜓
𝜕𝑥(𝑥) = 0. Therefore, 𝜓(𝑥) is a constant too.
As we assumed 𝜓(0) = 1, the constant is 1, so
𝜓(𝑥) = 1
Now we can write the function for the temperature (combining 𝐴 and 𝐵2 into one constant 𝐶𝑛)
𝑇(𝑥, 𝑡) = 1 + ∑𝐶𝑛𝑒−𝑘𝜆𝑛2 𝑡
∞
1
sin(𝜆𝑛𝑥)
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 𝐶𝑛
0 = 1 + ∑𝐶𝑛𝑒−𝑘𝜆𝑛
20
∞
1
sin (𝑛𝜋𝑥
2𝑙)
∑𝐶𝑛1
∞
1
sin (𝑛𝜋𝑥
2𝑙) = −1
∑𝐶𝑛
∞
1
sin (𝑛𝜋𝑥
2𝑙) sin (
𝑚𝜋𝑥
2𝑙) = −1sin (
𝑚𝜋𝑥
2𝑙)
∫∑𝐶𝑛 sin (𝑛𝜋𝑥
2𝑙) sin (
𝑚𝜋𝑥
2𝑙) 𝑑𝑥
∞
1
𝑙
0
= ∫−1sin (𝑚𝜋𝑥
2𝑙) 𝑑𝑥
𝑙
0
∑𝐶𝑛 ∫sin(𝑛𝜋𝑥
2𝑙) sin (
𝑚𝜋𝑥
2𝑙)𝑑𝑥
𝑙
0
∞
1
= −∫sin(𝑚𝜋𝑥
2𝑙)𝑑𝑥
𝑙
0
∑𝐶𝑛𝑙
2
∞
1
= −∫sin (𝑛𝜋𝑥
2𝑙)𝑑𝑥
𝑙
0
∑𝐶𝑛𝑙
2
∞
1
= (2l
nπcos (
𝑛𝜋𝑥
2𝑙))
0
𝑙
𝐶𝑛 =4
𝑛𝜋[cos (
𝑛𝜋
2) − cos(0)]
𝐶𝑛 = −4
𝑛𝜋
The solution can be written simply as
𝑇(𝑥, 𝑡) = 1 − ∑4
𝑛𝜋𝑒−𝑘𝜆𝑛
2 𝑡
∞
1
sin(𝜆𝑛𝑥)
Where 𝜆𝑛 =𝑛𝜋
2𝑙 and 𝑛 = 1, 3, 5, …
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
First, we apply the approximation for the second degree derivative
𝜕𝑇
𝜕𝑡=
𝑘
Δ𝑥2[𝑇𝑖−1 − 2𝑇1 + 𝑇𝑖+1]
Now we can approximate the temperature of the 𝑖𝑡ℎ point of the rod at the 𝑛𝑡ℎ point in time
applying Euler’s explicit method
𝑇𝑖𝑛+1 = 𝑇𝑖
𝑛 +𝑘Δ𝑡
Δ𝑥2[𝑇𝑖−1
𝑛 − 2𝑇𝑖𝑛 + 𝑇𝑖+1
𝑛 ]
Where 𝑘Δ𝑡
Δ𝑥2 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 don’t 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 doesn’t 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 = 𝑏�⃗� 𝑛
Where �⃗� 𝑛 = {
𝑇1𝑛
𝑇2𝑛
…𝑇𝐼−1
𝑛
} and 𝑏 is the following matrix
1 0 0 0 ⋯ 0 0 0 0 𝛽 1 − 2𝛽 𝛽 0 ⋯ 0 0 0 0 0 𝛽 1 − 2𝛽 𝛽 ⋯ 0 0 0 0 ⋮ ⋮ ⋮ ⋮ ⋱ 0 0 0 0 0 0 0 0 ⋯ 𝛽 1 − 2𝛽 𝛽 0 0 0 0 0 ⋯ 0 0 𝛽 1 − 𝛽
Notice that the product between the two matrices doesn’t 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 2 3 4 𝐼 20 25 30 35 𝛥𝑡 0.00125 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
the inverse of the square of 𝐼 (𝑓𝑜𝑟 𝛽 ∝1
Δ𝑥2 𝑎𝑛𝑑 Δ𝑥 ∝1
𝐼). 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 ∗ 10−4 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
Full Code for Question 2
clear, clc
% Defining the spatial grid size and the time step I = 35; dt = 0.0004082;
% Setting the length and the constant k as 1 l = 1; k = 1;
% Calculating spatial step dx, the vector x for the plot % and the amount of time steps N dx = l/I; x = linspace(0, l, I); x = x'; t = 0.02; N = t/dt;
% Creating a matrix with the temperatures at initial instant. For % calculations, the last point is not considerated now T = zeros((I-1), 1); T(1) = 1;
% Calculating the CFL constant beta = k*dt/(dx)^2;
% Calculating the matrix b used in the multiplication to find each new % vector T with the new temperatures b = zeros(I-1); b(1,1) = 1; b(I-1,I-2) = beta; b(I-1,I-1) = 1 - beta;
for i=2:I-2 b(i,i-1) = beta; b(i,i) = 1 - 2*beta; b(i,i+1) = beta; end
% Calculating the temperatures for each point for i=1:N T = b*T; end
% Creating a vector y to plot the results. The last element of this vector % has the same value of the second to last, because their temperatures are % the same y = zeros(I,1); for i = 1:I-1 y(i) = T(i); end y(I) = y(I-1);
% 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*((i-
1)*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');
Top Related