Math340 hw6

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Math340 HW6

Programming in Mathematics
Due October 25, 2024

Student Name: ID

Recommended Report Format


Please use the homework template as a Google Colab document (https://
bit.ly/476Eocm) to complete your report, ensuring it includes the following
sections:

(1) A Concise Summary (e.g., one paragraph)

(2) Methodology

(3) Code and Results (e.g., Tables + Figures)

Tasks for Submission

(a) Complete a brief report following the provided format and save it as a
PDF.

(b) Submit the report file to Canvas and check the similarity test results.
Ensure the similarity percentage is below 20%, or seek approval from
the TA or Instructor if it exceeds this limit.

(c) Submit Codes in Jupyter format as the second file to Canvas.

1
1: [35 points] Examine the exponential function f (x) = ex and its first-
and fourth-order Taylor series, denoted as f (1) (x) and f (4) (x), respectively.
Execute the following tasks to construct a 4-panel plot over the interval
x ∈ [0, 3]:

(a) In panel (a), illustrate the solutions of f (x) and f (1) (x), including the
necessary legends.

(b) In panel (b), display the relative error obtained by computing the dif-
ferences between f (x) and f (1) (x).

(c) In panel (c), illustrate the solutions of f (x) and f (4) (x), including the
necessary legends.

(d) In panel (d), display the relative error obtained by computing the dif-
ferences between f (x) and f (4) (x).

2: [35 points]
Consider the provided solutions for control and parallel runs, denoted as yc
and yp respectively:
yc = y0 eσt , (1)
yp = (y0 + )eσt . (2)
These solutions derive from solving the ordinary differential equation (ODE)
given by Eq. 1 of HW5:
y 0 = σy, (3)
subject to the initial conditions, y(0) = y0 and y(0) = (y0 + ) correspond-
ingly. Consequently, the parallel run represents the solution to the system
with an error () in the initial condition. In Eqs. (1) and (2), we set σ = 0.2.
To determine the growth rate σ numerically for the time interval between 0
and 10 with dt = 0.001, complete these tasks

(a) Compute ln(yn+1 /yn )/dt, using either yc or yp .

(b) Compute ln((yp − yc )/)/t

(c) Repeat the above steps using a larger dt (e.g., dt = 1) and compare the
results with the previous outcomes.

2
(d) Apply np.var and np.mean to analyze your results.

Here, yn = y(t) at t = ndt.

3: [15 points]
Use the random.choice() function to accomplish the following task:

(*) Produce six double-digit numbers, ensuring that there are three odd
numbers and three even numbers, all of which are unique.

4 [15 points]

(a) Explore the concept of mutable and immutable variables. [7 points]

(b) Explore the differences between Python’s ”int” data type and Numpy’s
”int” type. [3 points]

(c) Based on the concept in (a), please analyze and compare the disparities
between the second and third lines of code. [5 points]

a=1

a=a+1
a+=1

You might also like