Math340 hw6
Math340 hw6
Math340 hw6
Programming in Mathematics
Due October 25, 2024
Student Name: ID
(2) Methodology
(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.
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
(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.
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]
(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