Math 228B Problem Set 2 Solutions

Embed Size (px)

Citation preview

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    1/22

    Solutions to the Second Problem Set

    Michael Ishigaki

    Mathematics 228b

    University of California, Berkeley

    February 23, 2012

    1

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    2/22

    Problem One

    Prompt. Consider the partial differential equation given by

    ut = uxx + uyy + uzz (1)

    Part 1

    Prompt. Derive a stability requirement on = kh2

    (what is h?)Response. To derive a stability requirement on , we will do a Fourier stabilityanalysis. We let =

    1 2 3

    and j =

    j1 j2 j3

    . Fourier series

    gives us,

    uj =1

    233

    eij u() d, u() =

    j

    eijuj

    and Parsevals theorem gives us,

    |uj |2

    =1

    233

    |u()|

    2 d

    Our scheme is,

    un+1 = un + k

    3

    m=1

    D+mDm

    un =

    I +

    3

    m=1

    S+m 2I + Sm

    un

    Putting our scheme into the Fourier transform for u,

    un+1 =

    I +

    3

    m=1 S+m 2I + Sm

    1

    233

    eij un() d

    =1

    (2)3

    eij +

    3

    m=1

    eij(+m) 2eij + eij(+m)

    un() d

    =1

    (2)3

    eij

    1 + (2i)2

    3m=1

    eim 2 + eim

    (2i)2

    un() d

    un+1 =1

    (2)3

    eij

    1 4

    3

    m=1

    sin2(

    2)

    un() d

    This implies an amplification factor,

    () = 1 43

    m=1

    sin2(

    2)

    We need |()| 1. Where = kh2

    this implies,

    1

    23

    m=1 sin2( 2 )

    2

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    3/22

    And since sin2( 2) < 1,

    1

    6

    is our stability requirement on .For (1), we have the interpretation of h as the spatial step size. More specif-

    ically, since we are taking spatial steps in three directions (corresponding to ourthree dimensions), we have h as the common spatial step size. That is, the stepsizes in all directions are each equal to h.

    Part 2

    Prompt. Transform (1) into spherical coordinates.Response. We will transform our Cartesian coordinates into spherical coordi-nates,

    x y z

    as follows,x y z

    x2 + y2 + z2 arccos(z

    ) arctan( yx

    )

    If so inclined, we could transform from spherical coordinates into Cartesiancoordinates as follows,

    cos() sin() sin() sin() cos()

    We now begin with the transformation of (1) into spherical coordinates. Notingthat (1) can be written as

    ut = 2u

    where 2 is the Laplacian operator, we obtain (1) in spherical coordinates byusing the Laplacian operator transformed into spherical coordinates,

    2 =

    1

    2

    2

    +

    1

    2 sin()

    sin()

    +

    1

    2 sin2()

    2

    2

    And so we get,

    ut = 2u

    =

    1

    2

    2

    +

    1

    2 sin()

    sin()

    +

    1

    2 sin2()

    2

    2

    u

    =1

    2

    2

    u

    +

    1

    2 sin()

    sin()

    u

    +

    1

    2 sin2()

    2u

    2

    ut

    =2u

    2+

    2

    u

    +

    1

    2

    2u

    2+

    cos()

    2 sin()

    u

    +

    1

    2 sin2()

    2u

    2(2)

    where (2) is our original PDE, (1), in spherical coordinates.

    3

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    4/22

    Part 3

    Prompt. Solve the problem ut = 2

    u in spherical coordinates with initialcondition u(R, t = 0) = 1 for 0 R < 1 and boundary condition u(1, t) = 0.Solve this up to time T = 1.Response. Noting that this problem is the heat equation for a sphere withinitial and boundary conditions that are not dependent on the angles or ,we can use spherical symmetry to solve this problem in , the radius. This isbecause, given any radius and time t, the value of u(t, , , ) is constantfor all and due to our spherically symmetric conditions. Therefore, we havethat,

    u

    = 0,

    u

    = 0

    And so, to construct a finite difference scheme for this problem, we will considerthe equation,

    ut =2u2

    + 2

    u

    which is equation (2) after exploiting spherical symmetry. This equation sug-gests the following finite difference scheme,

    Dt+un = D+Du

    n +2

    jD0u

    n

    where j are the discretized radii. Where k is our time step and h is our spatial(radius) step, after expanding our finite difference notation we get,

    un+1j unj

    k=

    unj+1 2unj + u

    nj1

    h2+

    2

    j

    unj+1 unj1

    2h

    which implies,

    un+1j =

    k

    h2+

    k

    hj

    unj+1 +

    1 2

    k

    h2

    unj +

    k

    h2

    k

    hj

    unj1

    This suggests the following coefficient matrix,

    1 2 kh2

    kh2

    + kh1

    0 0 . . . 0 0kh2 k

    h21 2 k

    h2kh2

    + kh2

    0 . . . 0 0

    0 kh2 k

    h31 2 k

    h2kh2

    + kh3

    . . . 0 0...

    ......

    .... . .

    ......

    0 0 0 0 . . . kh2 k

    h1/h1 2 k

    h2

    where our method becomesun+1 = Aun

    where A is the above matrix. Noting that we seek the solution also at 1 = 0,we cannot evaluate this coefficient matrix since we will encounter division by 0.This occurs when weighting the value of un2 during the calculation of u

    n+11 .

    4

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    5/22

    This motivates us to consider a finite difference scheme without the centraldifference on the second term of (2) after exploiting spherical symmetry. We

    get the following,

    Dt+un = D+Du

    n +2

    jD+u

    n

    After expanding, we obtain

    un+1j unj

    k=

    unj+1 2unj + u

    nj1

    h2+

    2

    j

    unj+1 unj

    h

    which implies,

    un+1j =

    k

    h2

    unj1 +

    1

    2k

    h2

    2k

    jh

    unj +

    k

    h2+

    2k

    jh

    unj+1

    However, as before, we encounter division by 0. This occurs when weighting the

    value of un1 during the calculation of un+11 .To find a creative solution to this problem, we will define a new difference

    which allows us to bypass division by 0 by exploiting symmetry and consideringa special difference,

    D :=unj+2 u

    nj2

    4h

    which gives the following scheme,

    Dt+un = D+Du

    n +2

    jDu

    n

    Or in expanded notation,

    un+1j unj

    k =

    unj+1 2unj + u

    nj1

    h2 +2

    j

    unj+2 unj2

    4h

    which implies,

    un+1j =

    k

    2hj

    unj2 +

    k

    h2

    unj1 +

    1

    2k

    h2

    unj +

    k

    h2

    unj+1

    +

    k

    2hj

    uj+2

    If we only apply this scheme to the calculation of un+11 , then we can exploitsymmetry further and get the following,

    un+1

    1

    = k2hj

    un1 + kh2un0 + 1 2k

    h2un1 + k

    h2un2 + k

    2hj u3

    =

    k

    2hj

    un3 +

    k

    h2

    un2 +

    1

    2k

    h2

    un1 +

    k

    h2

    un2 +

    k

    2hj

    u3

    un+11 =

    1

    2k

    h2

    un1 +

    2k

    h2

    un2

    5

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    6/22

    This scheme combined with the previous scheme implies the following coefficientmatrix,

    1 2kh2

    2kh2

    0 0 . . . 0 0kh2

    12kj+2kh

    h22

    kj+2khh22

    0 . . . 0 0

    0 kh2

    12kj+2kh

    h23

    kj+2khh23

    . . . 0 0...

    ......

    .... . .

    ......

    0 0 0 0 . . . kh2

    12kj+2khh21/h

    This coefficient matrix successfully avoids division by 0. We let the above matrixbe denoted by A and consider the scheme,

    un+1 = Aun (3)

    After implementing this scheme in MATLAB, we obtain solutions that ap-pear correct from a physical intuition. The following were computed with valuesof (k, h) as ( 110 ,

    12,000 ), (

    110

    , 120,000 ), (

    110

    , 19,000,000) respectively and represent the

    solution at time T = 1,

    u = 104

    0.72480.68790.65230.60140.53410.45300.36220.2665

    0.17100.08060.0000

    , u = 104

    0.74530.70740.67080.61840.54920.46590.37250.2740

    0.17580.08290.0000

    , u = 104

    0.74760.70960.67290.62030.55090.46730.37360.2749

    0.17630.08320.0000

    The following are plots of the solution at various times (measured in itera-tions where h = 1100 and k =

    1900,000 so iterations varied across time from 0 to

    900, 000). The plots are in chronological order.

    0 0.2 0.4 0.6 0.8 1

    0

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 0

    0 0.2 0.4 0.6 0.8 1

    0

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 25000

    6

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    7/22

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u

    )

    Plot at iteration 50000

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u

    )

    Plot at iteration 100000

    0 0.2 0.4 0.6 0.8 10

    0.1

    0.2

    0.3

    0.4

    Radius (rho)

    Heat(u)

    Plot at iteration 200000

    0 0.2 0.4 0.6 0.8 10

    0.5

    1x 10

    4

    Radius (rho)

    Heat(u)

    Plot at iteration 900000

    Alternatively, we may seek to resolve the division by 0 analytically. Wedo this by observing what happens to the second term of our equation as weapproach a radius of 0,

    lim0

    2

    u

    = lim

    02

    2u

    2

    And so, we can represent our partial differential equation as follows,

    ut =

    3

    2u2

    , = 02u2

    + 2u

    , = 0

    Now we will construct a difference scheme for this piecewise function as follows,

    Dt+u =3D

    +Du,

    j= 0

    D+Du +2

    D+u, j = 0

    Or in expanded notation,

    un+1t unt

    k=

    3unj+12u

    nj +u

    nj1

    h2, j = 0

    unj+12unj +u

    nj1

    h2+ 2

    j

    unj+1unj

    h, j = 0

    Which simplifies to,

    un+1t =

    3 kh2

    unj1 +

    1 6 kh2

    unj + 3

    kh2

    unj+1, j = 0

    kh2

    unj1 + 1 2k

    h2 2k

    jhunj +

    kh2

    + 2kjh

    unj+1, j = 0

    Since this scheme has no division by j , it manages to avoid the division by 0problem that we were earlier encountering. We create a coefficient matrix in

    7

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    8/22

    the same fashion as we did twice above. This gives,

    1 6kh2 3

    kh2 0 0 . . . 0 0

    kh2

    12kj+2kh

    h22

    kj+2khh22

    0 . . . 0 0

    0 kh2

    12kj+2kh

    h23

    kj+2khh23

    . . . 0 0...

    ......

    .... . .

    ......

    0 0 0 0 . . . kh2

    12kj+2khh21/h

    We denote this matrix by A and consider the method,

    un+1 = Aun (4)

    After computing our new method in MATLAB, we obtain the followingresults with values of(k, h) as ( 110 ,

    12,000 ), (

    110 ,

    120,000 ), (

    110 ,

    19,000,000 ) respectively

    and represent the solution at time T = 1,

    u = 104

    0.62020.60960.58520.54290.48410.41170.32980.24300.15600.07360.0000

    , u = 104

    0.63820.62720.60210.55860.49810.42360.33930.25000.16050.07570.0000

    , u = 104

    0.64020.62920.60400.56040.49960.42490.34040.25080.16100.07600.0000

    The following are plots of the solution at various times (measured in itera-tions where h = 1100 and k =

    1900,000 so iterations varied across time from 0 to

    900, 000). The plots are in chronological order.

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 0

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 25000

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 50000

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 100000

    8

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    9/22

    0 0.2 0.4 0.6 0.8 10

    0.1

    0.2

    0.3

    0.4

    Radius (rho)

    Heat(u

    )

    Plot at iteration 200000

    0 0.2 0.4 0.6 0.8 10

    0.5

    1x 10

    4

    Radius (rho)

    Heat(u

    )

    Plot at iteration 900000

    Codes. prob1part3.m (Takes in h and k as inputs and solves problem 1 part3 using the special divided difference D. If the lines within the f or statementare uncommented, then this function will plot an animation of the heat acrossa line extending from the center of the sphere to the perimeter of the sphere.),prob1part3b.m (Takes in h and k as inputs and solves problem 1 part 3 using thepiecewise form of the partial differential equation that was obtained by takingthe limit as r 0. If the lines within the f or statement are uncommented, then

    this function will plot an animation of the heat across a line extending from thecenter of the sphere to the perimeter of the sphere.)

    Part 4

    Prompt. Solve the problem ut = 2u in spherical coordinates with initial

    condition u(R, t = 0) = 1 for 0 < R < 1 and boundary conditions u(0, t) = 1and u(1, t) = 0. Solve this up to time T = 1.Response. First, we use the scheme (3) derived above but we introduce dif-ferent boundary conditions. After implementing the scheme in MATLAB, weobtained results that seemed physically correct. The following were computedwith values of (k, h) as ( 110 ,

    12,000), (

    110

    , 120,000 ), (

    110

    , 19,000,000 ) respectively and

    represent the solution at time T = 1,

    u =

    1.00000.45000.26670.17500.12000.08330.05710.03750.02220.01000.0000

    , u =

    1.00000.45000.26670.17500.12000.08330.05710.03750.02220.01000.0000

    , u =

    1.00000.45000.26670.17500.12000.08330.05710.03750.02220.01000.0000

    These results show what appears to be impressive convergence for this problem.The following are plots of the solution at various times (measured in itera-

    tions where h = 1100 and k =1

    900,000 so iterations varied across time from 0 to

    900, 000). The plots are in chronological order.

    9

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    10/22

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u

    )

    Plot at iteration 0

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u

    )

    Plot at iteration 25000

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 50000

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 100000

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 200000

    0 0.2 0.4 0.6 0.8 10

    0.5

    1

    Radius (rho)

    Heat(u)

    Plot at iteration 900000

    We now use the scheme (4) derived above to solve this problem. After imple-menting the scheme in MATLAB, we obtained results that again seemed phys-ically correct. The following were computed with values of (k, h) as ( 110 ,

    12,000),

    ( 110 ,1

    20,000 ), (110

    , 19,000,000 ) respectively and represent the solution at time T = 1,

    u =

    1.0000

    0.45000.26670.17500.12000.08330.05710.03750.02220.01000.0000

    , u =

    1.0000

    0.45000.26670.17500.12000.08330.05710.03750.02220.01000.0000

    , u =

    1.0000

    0.45000.26670.17500.12000.08330.05710.03750.02220.01000.0000

    These results, to the precision at which they appear, are identical to thoseobtained when we used scheme (3).

    A moment of thought about the physical intuition behind this problem leadsone to question what happens to the results when the spatial step size is reduced.This question arises from perplexity as one wonders whether or not such aphysical situation is even possible. This question is also motivated by the largedifference between the first and second components of the above vectors whichresulted from computing this problem with a fairly large spatial step size.

    10

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    11/22

    We will next show results that were computed with values of (k, h) as( 110 ,

    19,000,000 ), (

    1100 ,

    19,000,000), (

    11000 ,

    19,000,000) respectively and represent the so-

    lution at time T = 1. It is very important to note that these vectors are nottheir true lengths. For the first vector, corresponding to (k, h) = ( 110 ,

    19,000,000),

    all vector components are shown. For the second vector, corresponding to(k, h) = ( 1100 ,

    19,000,000 ), only every tenth component is shown. And for the

    third vector, corresponding to (k, h) = ( 11000 ,1

    9,000,000 ), only every hundredthcomponent is shown. This is done so that these three vectors can be comparedside-by-side with each computed value of u compared with other computed val-ues of u corresponding to the same absolute positions on the radius.

    u =

    1.00000.45000.26670.1750

    0.12000.08330.05710.03750.02220.01000.0000

    , u =

    1.00000.08190.03820.0226

    0.01470.00990.00660.00430.00250.00110.0000

    , u =

    1.00000.00900.00410.0024

    0.00160.00110.00070.00050.00030.00010.0000

    It is clear from these results that as we decrease our spatial step size, oursolution changes. This does not sound particularly alarming at first. But whenone considers how we compared computed values of u at corresponding absolutepositions on the radius, one sees that a very interesting phenomenon is occurring:it appears our problem is actually dependent on our method.

    Codes. prob1part4.m (Takes in h and k as inputs and solves problem 1 part4. If the lines within the f or statement are uncommented, then this functionwill plot an animation of the heat across a line extending from the center of thesphere to the perimeter of the sphere.)

    Part 5

    Prompt. Has your stability requirement been altered? What is it in sphericalcoordinates?Response. To determine whether or not our stability requirement has beenaltered, we look at the influencing terms from our method (4),

    un+1t = 3 kh2

    unj1 +

    1 6 k

    h2

    unj + 3

    kh2

    unj+1, j = 0

    kh2 un

    j

    1+ 1 2k

    h2

    2k

    jhun

    j+ k

    h2 +

    2k

    jhun

    j+1, j = 0

    The terms that could influence stability are those which may become negativeas k and h vary. These terms both correspond to weighting the value of unj inthe method and are,

    1 6k

    h2, 1

    2kj + 2kh

    jh2

    11

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    12/22

    So we want to see for what values of h and k do we have,

    1 6 kh2

    0, 1 2kh2

    2kjh

    0

    where j = 0 in the first and 0 < j 1 in the second. The first gives us backour original stability requirement,

    k

    h2

    1

    6

    and the second gives

    1 2k

    jh+

    2k

    h2=

    2kh + 2kjh2j

    so, h2j 2kh + 2kj

    This then implies,k

    h2

    j

    2h + 2j

    As j 0, we have,k

    h2 0

    Which is always satisfied. Therefore, our stability requirement is,

    k

    h2

    1

    6

    Which has not been altered. In spherical coordinates, interpreting h as thespatial step across the radius. Which could also be written as,

    k

    21

    1

    6

    Where we then note that 1 = h when we are working with spherical coordinatesfor this problem.

    Problem 2

    Prompt. How hot can a swimming pool get? Consider a unit square cube anduse the differential equation ut =

    2u. On all walls except the top, assumeinsulating boundary conditions (i.e. du

    dn= 0 where n is the normal vector). On

    the top surface, we have the boundary condition u = 1 during the day and u = 0at night.

    12

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    13/22

    Part 1

    Prompt. Find, as a function of the ratio of day length/night length, the maxi-mum temperature reached at the bottom of the pool after 5 cycles of day/night.Assume initial condition u = 0. Use a variable time cycle.Response. We first seek a finite difference method that will allow us to solvethe desired partial differential equation,

    ut = 2u

    =2u

    x2+

    2u

    y2+

    2u

    z2

    ut = uxx + uyy + uzz

    on a cube with Neumann boundary conditions,

    un

    = 0

    on all faces of the cube except for the top and with Dirichlet boundary condi-tions,

    uni,j,k =

    1, day

    0, nig ht

    on the top face of the cube (when k = 1).We begin by seeking a solver to use within the faces of the cube. We will

    use the following finite difference approximation,

    un+1 = Dx+Dx

    un + Dy+Dy

    un + Dz+Dz

    un

    After expanding our notation we obtain,

    un+1i,j,k uni,j,k

    kt=

    uni+1,j,k 2uni,j,k + u

    ni1,j,k

    h2+

    uni,j+1,k 2uni,j,k + u

    ni,j1,k

    h2

    +uni,j,k+1 2u

    ni,j,k + u

    ni,j,k1

    h2

    Where kt is the time step and h is the spatial step. Here we have chosen thatthe spatial step in the x, y, and z directions will all be equal. Which, expandingfurther and substituting := kt

    h2, gives,

    un+1i,j,k = uni+1,j,k + u

    ni1,j,k + u

    ni,j+1,k + u

    ni,j1,k + u

    ni,j,k+1 + u

    ni,j,k1

    + (1 + )6u

    n

    i,j,k

    Now we seek to fulfill our boundary conditions. To enforce our Neumannboundary conditions we observe that we can achieve,

    u

    n= 0

    13

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    14/22

    by increasing the width, heigh and depth of our cube each by 2 discretizedspatial units. This allows us to think of our cube as residing within a larger

    cube with a padding equal to 1 discretized spatial unit within each face. Fromthis point on, we will consider our problem in this manner. So our indices nowtake on values 1 i,j,k 1

    kt+ 3. To ensure that the Neumann condition is

    satisfied, we then enforce,

    uni,j,k =

    uni+1,j,k, i = 1

    uni1,j,k, i =1kt

    + 3

    uni,j+1,k, j = 1

    uni,j1,k, j =1kt

    + 3

    uni,j,k+1, k = 1

    uni,j,k1, k =1kt

    + 3

    For our out-most corners, we have points with undetermined values. Sincethe Neumann conditions are only concerned with the rate in the direction ofthe norm, since our methods stencil does not contain diagonals, and since theout-most corners will not appear in our final solution, we are free to choose theirvalues. In the accompanying code, we chose to set the values of the corners equalto one of the other out-most elements neighboring them.

    To enforce our Dirichlet boundary conditions, we can first set up an intuitiveclock system. To deal with our days, nights, and cycles of days, we set upa clock system using modular arithmetic. We set our clocks full day to beTfd := (Ld + Ln)

    1kt

    where Ld is the unitless length of a day, Ln is the relativelyunitless length of a night and kt is our time step. We denote the units of ourclock to be CTs, which stand for Clock Times. So, for example, in CTs, wehave that the night length as Tn := Ln

    1kt

    and the day length as Td := Ld1kt

    .

    Now we define the current time in CTs, ti to be our current iteration throughthe day where the current time begins at 0 and ends at Tfd d where d is thenumber of day cycles. We define the current modular clock time to be

    tc = ti (mod Tfd)

    It is now clear that we have a clock system with which we can determine whatday we are in and at what time of the day we are experiencing. This informationwill be used to control the Dirichlet boundary conditions of our problem and toprovide a way of controlling the number of day cycles. Now we can enforce ourDirichlet boundary conditions. Whenever we have k = 1, we set

    un

    i,j,k

    = 1, t 1 (mod Tfd) Td0, otherwise

    This works for our Dirichlet conditions, since the first cases condition is thatthe model is in day time. Otherwise, it is in night time.

    After implementing this scheme, we get very good computational results.We note that MATLAB also gives excellent algorithmic results because this

    14

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    15/22

    scheme is implemented in MATLAB very effectively using matrix operations.Similar algorithmic benefits can be achieved using Linear Algebra libraries for

    other languages.The following were obtained with h = 140 , kt =

    18000 , Ld =

    410 , Ln =

    310 .

    Thus, the following plots were obtained with a ratio LdLn

    = 1.333. These plotsare in chronological order.

    15

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    16/22

    When we vary the ratio of day length/night length and plot the results againstthe maximum temperature at the bottom of the pool after 5 cycles of day/night(while holding the total time in one day constant), we obtain the following,

    16

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    17/22

    0 1 2 3 4 5 6 7 8 9 100.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1Ratio of Day Length/Night Length versus Max Temperature at Bottom At End of 5 Cycles

    Ratio of Day Length/Night Length

    MaxTemperatureatBottomA

    tEndofCycles

    As we vary the time cycle, we obtain the following,

    0 1 2 3 4 5 6 7 8 9 100

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1Ratio of Day Length/Night Length versus Max Temperature at Bottom At End of 1 Cycle

    Ratio of Day Length/Night Length

    MaxTemperatureatBottomA

    tEndofCycles

    0 1 2 3 4 5 6 7 8 9 100

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1Ratio of Day Length/Night Length versus Max Temperature at Bottom At End of 2 Cycles

    Ratio of Day Length/Night Length

    MaxTemperatureatBottomA

    tEndofCycles

    0 1 2 3 4 5 6 7 8 9 100.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1Ratio of Day Length/Night Length versus Max Temperature at Bottom At End of 3 Cycles

    Ratio of Day Length/Night Length

    MaxTemperatureatBottomA

    tEndofCycles

    0 1 2 3 4 5 6 7 8 9 100.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1Ratio of Day Length/Night Length versus Max Temperature at Bottom At End of 7 Cycles

    Ratio of Day Length/Night Length

    MaxTemperatureatBottomA

    tEndofCycles

    These results are all similar. It seems the differences, which are very slight,may be attributed to how the day lengths, night lengths and overall length ofone day cycle interacted with the initial condition un=1i,j,k = 1 for our choices ofinput values or may be attributed to numerical error.Codes. prob2part1.m (Solves problem 2 part 1. This program takes in spatial

    17

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    18/22

    step size, time step size, day length (unitless), night length (unitless) and num-ber of days as input. If the variable okaytoplot is set as 1, then this function

    will plot a 3D animation of the solution in time.), prob2part1plots.m (Runsprob2part1 with specific inputs and plots the results to obtain the ratio of daylength/night length versus max temperature at the bottom of the pool as seenat the end of the response for problem 2 part 1.)

    Part 2

    Prompt. Deal with the angle of the sun on the pool.Response. The angle of the sun can be implemented into the problem bymodifying the Dirichlet boundary conditions at the top of the pool. We will dothis by making the Dirichlet boundary conditions depend on the current portionof the day time. To model this, we will assume that, during the day, the sunmoves continuously from = 0 to = where is the angle, in radians, betweenthe line from the origin to the position of the sun and the horizon (which weassume to be flat). At = 2 , the sun will be the hottest; this occurs in thereal world and is the reason why, given clear weather, the day is usually hottestat 12:00 pm. We will now derive an equation that gives us the portion of 1,the maximum temperature of the sun throughout the day, that depends on theangle, , of the sun.

    First we consider the case when 2 0. We can construct a nice functionfor a single point as the boundary condition for k = 1,

    uni,j,k = 1 cos()

    This works well since at = 0, cos() = 1 and so uni,j,k = 0 and at =2 ,

    cos() = 0 and so uni,j,k = 1. Now, when

    12 ,

    we will let =

    2cos( p)

    which goes from 2 to as p goes from12 to 1 and scales realistically. What is

    also implied is that our Dirichlet boundary condition remains the same duringthe night.

    18

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    19/22

    We do have a problem, however, in that our sun rises are very long and oursun sets are very long. To compensate for this, we will implement a scheme

    with the boundary condition on k = 1 as,

    uni,j,k =

    1 cos2(), 2 0

    1 sin2(), < 2

    The following were obtained with h = 140 , k =1

    8000 , Ld = 1, Ln =210 . Thus,

    the following plots were obtained with a ratio LdLn

    = 5.

    19

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    20/22

    We now make a very important note. As was implied by the above graphicalresults and the choices of day length and night length, when we are consideringthe angle of the sun in the problem, our definition for night time is when thesun is completely gone. Whenever the sun is rising or setting, we consider this

    day time. And so when modeling problems realistically, we should make ourday lengths much longer than we did in the earlier problem.

    Now we want to let this value depend slightly on the position of the point.Since the sun is so far from the earth, this difference in reality is probablynot noticeable and so one may claim this is not realistic. However, since theprevious problem had temperature values that were equal across each z-layer,we want to make this problem more interesting. So, realistic or not, we will now

    consider this problem. We will assume the sun moves across our surface from(x, y) = (0, 0) to (x, y) = (1, 1) axis. We will assume the sun rises at x = 0 andsets at x = 1. To do this, when 2 0, we let

    uni,j,k =

    1

    810 +

    110

    i1h+1

    + 110j

    1h+1

    cos2(), 2 0

    1

    810 +

    110

    1h+1i1h+1

    + 1101h+1j1h+1

    sin2(), < 2

    This gives the results that we hoped for as can be seen graphically below. Thefollowing were obtained with h = 140 , k =

    18000 , Ld = 1, Ln =

    210 . Thus, the

    following plots were obtained with a ratio LdLn

    = 5.

    20

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    21/22

    Although rather unrealistic, hopefully the above gives insight into how onemight construct a highly realistic model. Of course, if one were to do sucha realistic model, the changes in temperature across the surface of the poolwould be so slight that a great deal of precision and very small step sizes wouldprobably have to be used.Codes. prob2part2.m (Solves problem 2 part 2. This program takes in spatialstep size, time step size, day length (unitless), night length (unitless) and numberof days as input. If the lines within the f or statement are uncommented, thenthis function will plot a 3D animation of the solution in time.), prob2part2b.m(Solves the second, unrealistic, part of this response for problem 2 part 2. Thisprogram takes in spatial step size, time step size, day length (unitless), nightlength (unitless) and number of days as input. If the lines within the f or

    statement are uncommented, then this function will plot a 3D animation of thesolution in time.)

    21

  • 8/2/2019 Math 228B Problem Set 2 Solutions

    22/22

    Part 3

    Prompt. Use real physical constants in your problem.Response. To use real physical constants in our problem, we begin by consid-ering,

    ut = 2u

    where = .58 in water according to third party sources. This gives us a slightlyaltered scheme,

    un+1i,j,k = k

    uni+1,j,kuni,j,k

    h

    uni,j,kuni1,j,k

    h

    h+ k

    uni,j+1,kuni,j,k

    h

    uni,j,kuni,j1,k

    h

    h

    + k

    uni,j,k+1uni,j,k

    h

    uni,j,kuni,j,k1

    h

    h+ uni,j,k

    It is very easy to modify the scheme that we did in Part 2 to solve this scheme.Using third party sources, we find that the day length in San Francisco towardthe end of February in 2012 varied between 10.5 and 11.5 hours. So we choose aday length of 11 (unitless) relative to a night length of 13 (unitless). Preservingthis ratio, we pick Ld = .846 and Ln = 1. So in CTs, we have Td = .846

    1k

    andTd =

    1k

    and Tfd = 1.8461k

    .We will model this problem using the first scheme derived in Part 2. The

    plots look similar to those of the beginning of Part 2 and thus are not shown.After 5 cycles, we obtain a temperature at the bottom of the pool of .1848 withrealistic coefficients. This can be compared with results at the bottom of thepool using the scheme in the beginning of Part 2. Such results from Part 2follow, For Ld = .846 and Ln = 1, we get .0919. And for Ld = 1 and Ln = .5,we get .2289. For Ld = .5 and Ln = .5, we get .1987. And for Ld = 1 and

    Ln = .5, we get .2289. So, in Part 3 we got .1848 and in Part 2 with the sameday and night lengths, we got .0919. This difference was thus due to the = 1value for water.Codes. prob2part3.m (Solves problem 2 part 3. This program takes in spatialstep size, time step size, and number of days as input. If the lines within thef or statement are uncommented, then this function will plot a 3D animation ofthe solution in time.), prob2part1plots.m (Runs prob2part3 with specific inputsand plots the results to obtain the ratio of day length/night length versus maxtemperature at the bottom of the pool.)

    22