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

Summer 2022 Math 3607: Project 1

1     Tiling with Spiral Polygons                                       [25 points]

 

Figure 1: Tiling with spiral triangles.                  Figure 2: Tiling with spiral squares.

Figure 3: Tiling with spiral hexagons.

(a) Modify the function1  spiralgon .m from Homework 2 so that it now takes n, m, d_angle, d_rot, and shift. The additional input argument shift is a two-vector (a vector with two elements) and it shifts the center of all the polygons to the point ( shift(1), shift(2)).

Consequently, the plotting statement must now be changed to

plot(V(1,:)+shift(1),  V(2,:)+shift(2),  ’Color’,  C(i,:))

In addition, comment out the“ hold  off ”statement before the for loop. (b) Generate Figure 1 by following the steps below.

• Run spiralgon, letting n=3, m=21, d_angle=4 .5, d_rot=90, and shift=[0  0]’ and save V. Its first column is the location of the leftmost vertex. Follow the call with“ hold  off ”so that the image disappears. It was only executed to return V.

• Modify shift so that the next time you run this function, the leftmost vertex will be at the origin. Run spiralgon again and you have 1{6th of your figure.

• Now use a for loop and plot the next five spiral triangles. You have to add 60˝ to d_rot for each new spiral triangle and also shift shift by 60˝ .

(c) Generate Figure 2 by patching four spiral squares as in the previous part. Each of the four spiral squares is generated with m=41 squares. Systematically determine other input arguments so as to reproduce the shape. Explain your choice of inputs. (Hint. Pay attention to the direction of each spiral. Study the statements in Problem 5(b) of Homework 2. They were carefully chosen to ensure that all shapes are aesthetically configured.  Or read the instructions found in LM 6.8–34, 35.)

(d) Generate Figure 3. Each of the spiral hexagons is generated with m=51. Determine other input arguments so as to reproduce the shape. Justify your choice of inputs.

2     Array Operations                                                         [25 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 gain2  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,

monthlyAvg       ffi,

an{30fl

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.

2 An absolute gain is positive if it is the case that the most recent stock price is higher than the oldest stock price; it may be negative if it is the case that the most recent stock price is lower than the oldest stock price.  The word absolute here has nothing to do with the absolute value function  | ¨ |.

 

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,

monthlyMovingAvg   fl ,    where   bj   $&%1j k130jÿ“1k“

in which pk  is the kth element of adjclose.  You may use a loop.  You may also use an 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.

 

 

 

 

 

 

190

180

170

160

150

140

130

120

110

100

90

80

 

 

 

 

 

 

 

 


4600

 

Figure 4: Example output for part (g)