HW 209

profilepanag10
problems.pdf

Problem #1: Polar-Cartesian Coordinates Converter (practice using If-EndIf)

Polar coordinates are related to Cartesian Coordinates by the following equations:

𝑥 = 𝑟 cos𝜃 𝑦 = 𝑟 sin𝜃 𝑥2 + 𝑦2 = 𝑟2 𝜃 = 𝑎𝑟𝑐𝑡𝑎𝑛 ( 𝑦

𝑥 )

Create an application (User Interface Worksheet and Main Sub Procedure) to convert between Polar and Cartesian

coordinates anywhere in the x/y plane:

1. Create a User Interface Worksheet, including user instructions, an input/output area where the values of 𝑥, 𝑦, 𝑟, and 𝜃 (lengths in mm and angle in degrees) can be entered/written in labeled and named cells (one cell for each). Create a printable "Run" button for your user to execute your Sub.

2. Create a well-structured Sub procedure that will process values in these input/output cells according to this

logic:

a. If the 𝑥 and 𝑦 values are BOTH zero AND the 𝑟 and 𝜃 values are NOT BOTH zero, then calculate 𝑥 and 𝑦

corresponding to the given 𝑟 and 𝜃, and write the results.

b. If the 𝑟 and 𝜃 values are BOTH zero AND the 𝑥 and 𝑦 values are NOT BOTH zero, then calculate 𝑟 and 𝜃

corresponding to the given 𝑥 and 𝑦, and write the results.

c. For all other conditions, do nothing.

Test your sub procedure, and manually copy the results to a table on the worksheet. Be sure to test the following

cases:

x = 2.5 mm and y = 7.1 mm

r = 5.5 mm and θ = 149°

x = 0 mm and y = -7.1 mm

Notes:

1. Recall that if a cell is blank, VBA will read a 0 numeric value from it. 2. NOT BOTH zero has a different logical meaning that BOTH NOT zero.

Problem #2: Compute the Factorials of a Series of Numbers (practice using For-Next)

Create a User Interface Worksheet with a series of numbers 1 through 40 in column A (starting in row 3).

Create a well-structured Main Sub that will use a For-Next loop to successively read each number from column

A, calculate the factorial of the number, and then write the result to the same row in column B. Hint: Modify

your Factorial Sub created as a class exercise).

Create a printable "Run" button on the worksheet to run your Sub.

Problem #3: Maclaurin Series for Sin𝒙 (practice using Do-While)

Maclaurin series are named after the Scottish mathematician Colin Maclaurin. The Maclaurin series expansion

for the sine function is:

Where 𝑥 is in radians. The terms of the Maclaurin sine series expansion get smaller and smaller, due to the increasing factorial in the denominator. In applying this series, these diminishing terms are included until one is

found to be below a desired "tolerance" value for the result.

Create a well-structured Function procedure to calculate the factorial of any number (be sure to name this function

distinctly from the Sub created for Problem #2). Recall that a function gets its input as an input argument that is

passed to the function, and returns its result as the value of the function.

Create a well-structured Function procedure named "MySin" to calculate the sine of any input using the Maclaurin

sine series expansion, and a tolerance of 1E-5. Use your factorial function in this function.

On your worksheet for this problem, create the table shown on the right. Use your MySin

function to complete the table.

Compare your results with the Excel built-in Sin() function.

Problem #4: Complete Weighted Score Class Exercise (practice using arrays)

Complete the class exercise started on Thursday, July 21 (see the last 2 slides of this week’s class notes for the

problem requirements).