Principles of PDEs

16
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 โ€ฒ = โ€ฒโ€ฒ

description

An example of solving a PDE with MATLAB.

Transcript of Principles of PDEs

Page 1: Principles of PDEs

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

๐‘˜ ๐‘”โ€ฒ

๐‘”=

๐‘“โ€ฒโ€ฒ

๐‘“

Page 2: Principles of PDEs

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

Page 3: Principles of PDEs

๐‘‡(๐‘™, ๐‘ก) = 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๐‘™

Page 4: Principles of PDEs

๐ถ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

Page 5: Principles of PDEs

๐ถ๐‘› =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

Page 6: Principles of PDEs

โˆซ 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

๐‘›๐œ‹

Page 7: Principles of PDEs

(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

Page 8: Principles of PDEs

๐œ•๐‘‡

๐œ•๐‘ฅ(๐‘ฅ, ๐‘ก) = ๐œ“โ€ฒ(๐‘ฅ) + ๐‘“โ€ฒ(๐‘ฅ)๐‘”(๐‘ก)

๐œ•๐‘‡

๐œ•๐‘ฅ(๐‘™, ๐‘ก) = ๐œ“โ€ฒ(๐‘™) + ๐‘“โ€ฒ(๐‘™)๐‘”(๐‘ก) = 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๐‘™)

Page 9: Principles of PDEs

โˆซโˆ‘๐ถ๐‘› 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, โ€ฆ

Page 10: Principles of PDEs

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.

Page 11: Principles of PDEs

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

Page 12: Principles of PDEs

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 ๐‘š.

Page 13: Principles of PDEs

Attachments

Plots for the question 2

Page 14: Principles of PDEs
Page 15: Principles of PDEs

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);

Page 16: Principles of PDEs

% 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');