Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Spring 2022 Math 3607: Exam 1

2022

 

1    Surface Plot                                                                      [20 points]

 Plot the surface represented (parametrically) by

Use 0 < r < R of your own choice. Do this in a single code block; you do not need to write a script for this problem. Begin your code cclf.Aef the code block, include

axis  equal,  axis  off

 

Suggestions.

• Use sufficiently many points so that the generated figure looks reasonably smooth. Too many points, however, will make it look unaesthetic, and your code will run slow.

• You are free to modify the color theme using colormap function.

• For visually pleasing/familiar results, it is recommended that you pick r and R such that R/r is about 3/2.

 

2    Birthday Problem                                                            [25 points]

 This problem is adapted from LM 3.9–22 which contains a useful hint. It is also a continuation of a recent homework problem.

(a) Write a script threeBdayMatch.m which generates a group of n people randomly and de- nesre are at least three people with the same birthday. This script should take n as an input. Do this without using a loop nor an if-statement. Then print out the content of your script using type:

type  threeBdayMatch.m

(b) Write another script threeBdayMatchSims.m which runs the previous simulation multiple aulates an approximate probability of having at least three people with the same birthday. This script should take n and the number of simulations n_sims as inputs. Do this without using a loop nor an if-statement. Then print out the content of your script using type.

type  threeBdayMatchSims.m

(c) Call the script from part (b) with n = 30, 40, . . . , 100, each with 10 000 simulations by running the following code block.

 

n_sims  =  10000;

for  n  =  30:10:100

threeBdayMatchSims

end

Note. If your script contains lines using the input function such as

n  =  input(’Enter  the  number  of  people:  ’);

n_sims  =  input(’Enter  the  number  of  simulations:  ’);

comment them out, just as you were instructed for previous homework assignments.

 

3    Approximation of π                                                          [25 points]

 Each of the following sequences converges to π:

This is a continuation of a recent homework problem.  Here our focus is to use vectorized codes (no loops allowed) and to produce visual illustrations of the convergence behavior.  Answer each question in a single code block; you do not need to write a script for this problem.

(a) Generate two row vectors a = (a0, a1, a2, . . . , a30) and b = (b0, b1, b2, . . . , b30), without using a loop. Use semicolons to suppress outputs.

 

graph.  Circle the data points and connect them with lines.  Give the plot a title, label axes, and create legends as shown in the example figure below. Begin your code block with clf.

Note. The expression “plot an  against n” means that n is along the horizontal axis and an  is along the vertical axis.

(c) Now plot |an − π| and |bn − π| against n for n = 0, . . . , 30 on a single log-linear graph. To draw on a log-linear graph, just replace plot by semilogy.  Circle the data points and connect them with lines. Give the plot a title, label axes, and create legends as shown in the example figure below. Begin your code block with clf.


 

4    Array Operations                                                             [30 points]

 Load the stock price data for Company A from January 2000 through May 2018 by

T  =  load(’stocks.dat’);

The data file contains opening price, daily high/low, closing price, etc. In this problem, we will be working with the adjusted close price which is found on the 5-th column of T. Note that the stock data are ordered from most recent to oldest.


Answer each of parts (a) through (e) using ONE MATLAB statement in a single code block.  Do not use a loop nor an if-statement for parts (a) through (e).

(a)  Extract all adjusted close price into a single column vector with the oldest price appearing first

and the most recent price appearing last. Name the column vector as adjclose.

Instruction. For this part, put a semicolon at the end to suppress the output, adjclose, since it is very long.

(b) Save the number of the data in the vector adjclose as n. Show the output.      From this point onward, adjusted close price will be referred to simply as stock price.

(c) Calculate the absolute gain1 in stock price by taking the difference between the oldest and the most recent stock prices. Show the output.

(d) Calculate the relative gain in percentage by dividing the absolute gain by the initial stock price and multiplying it by 100. Show the output.

(e) Using adjclose, construct another column vector monthlyAvg whose elements are 30-day average stock prices, that is,

        

where a1  is the average stock prices of the first 30 days, a2  is the average stock prices of the second 30 days, etc.

Instruction.  For this part, put a semicolon at the end to suppress the output, monthlyAvg,

since it is very long.



Answer each of parts (f) and (g) in a single code block.  For these parts, you are allowed to use loops.

(f) Using adjclose, construct the column vector monthlyMovingAvg whose elements are 30- day moving average stock prices, that is,

if-statement. But to earn full mark on this part, do it without using an if-statement. Correct solutions using if-statements will receive partial credits.

Instruction. Do not show the output.

Warning! Be sure to use MATLAB functions that were introduced in class. A use of special- ized functions that were not discussed in lectures, lecture notes, textbooks, or supplementary materials will not earn any credit.

(g)  Using  adjclose and monthlyMovingAvg, plot the stock prices and their 30-day moving

averages in a single graph. Create a title, label the graph, and create a legend as shown below. Begin your code block with clf. At the end of your code block, include

xlim([n-729,  n])

to show only the last two years of the data. Here n is the variable created in part (b). Hint. You may use 1:n as x-data for plotting, but it is not necessary.