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

Spring 2022 Math 3607:  Exam 1

1    Surface Plot                                                                              [20 points]

" Plot the surface represented (parametrically) by

Y__ x(◊ , Ï) = (R + r cos ◊)cos Ï

] y(◊ , Ï) = (R + r cos ◊)sin Ï          for ◊ , Ï œ [0, 2fi].

__[ z(◊ , Ï) = r sin ◊

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.Atef 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 10000 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 fi

" Each of the following sequences converges to fi:

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.                          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),

loop. Use semicolons to suppress outputs.

(b)  Using a and b from the previous part, plot an  and bn  against n for n = 0,..., 30 on a single

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 ≠ fi| and |bn ≠ fi| 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.

 


[25 points]

 

without using a


 

 

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,

S  a1   T

W(W)  a2    X(X)

monthlyAvg =  W(W)  a3    X(X) ,

W         X

W    .    X

Uan/30V

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

 

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

 

 

1An absolute gain is positive if it is the case that the most recent stock price is higher than the oldest stock price;

absolute here has nothing to do with the absolute value function | · |.

 

 

block.  For these parts, you are allowed to use

 

(f)  Using adjclose, construct the column vector monthlyMovingAvg whose elements are 30-

 Sb1T                  Y__ 1   j

 


in which pk  is the kth element of  adjclose.   You may use a loop.   You may also use an

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-

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

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.

!