Me programming

profileAyoub-94
209_hws.zip

Homework#2.pdf

ME209 Section #10474

Homework #2

Centigrade to Fahrenheit Converter

Temperature can be converted from Celsius to Fahrenheit using the formula:

F=1.8C 32

Write a Function that takes the temperature in degrees Celsius as an input argument, calculates

the equivalent temperature in degrees Fahrenheit using the above equation, and returns the result

as the function value. Initially, name your function C2F.

Are you having any trouble using C2F as the name of your function? You should be, because of

an idiosyncrasy of Excel. Excel thinks that you meant to type the address of worksheet cell CF2

(second row, 85th column), and wants to correct it for you. Worse yet, Excel won't take "No" for

an answer. Frustrating, isn't it? There are many such idiosyncrasies in Excel. When having

trouble, one of the things to try is changing the name of your procedure or variable; it may be

conflicting with something reserved by Excel or VBA.

To get your function to work, rename it to something like Cent2F. Try your function in

worksheet cells A1, A2, and A3 using C = -40°, C = 20°, and C = 100°, respectively.

Column Buckling

Consider a column with a square cross-section, loaded with a force as shown in the figure below.

The critical buckling load, F, which will cause the column to buckle, is given by the formula

shown. The parameter E is the elastic modulus of the material, I is the area moment of inertia of

the beam, and L is the length of the beam. Parameter K is known as the dimensionless effective

length factor, which takes into account the type of column support condition at each end.

A. Create the following tables on the user interface worksheet to contain the values of the effective

length factors and elastic modulus of the materials steel, aluminum, and wood. Use the Internet

to find appropriate values for the elastic modulus. Note that most property tables list these

values in units of GPA (gigapascals, or 10^9 N/m^2).

B. Create two named input cells for the beam length, L (in meters), and square cross-section

dimension, d (in millimeters), and properly label these input cells. Use L = 2 m and d=3 mm

as initial inputs for these parameters.

C. Create the following results table on the user interface worksheet to contain the resulting

critical buckling load (F) for each case of material and effective length factor.

D. Write a VBA Function to calculate the critical buckling load for a column, with the four

required inputs (K, E, L, and d) passed from the worksheet as function arguments. Research

the equation for the area moment of inertia of a square cross-section beam, and use that

equation in your function to calculate I.

E. Use your function in each of the critical buckling load table cells. Use relative vs. absolute

cell referencing wisely, so that cell references passed to your function can be copied (Ctrl-C)

and pasted (Ctrl-V) without having to manually correct them.

F. Add the correct units of the resulting critical buckling load to the results table header.

End fixtures K value

Pinned 1

Fixed 0.5

Fixed-Pinned 0.699

Fixed-Free 2.0

Material Elastic Modulus (GPa)

Steel (look up this value on the Internet)

Aluminum (look up this value on the Internet)

Wood (look up this value on the Internet)

F

__MACOSX/._Homework#2.pdf

hw3.pdf

Incandescent Space Heating

When energy is added to a fluid (liquid or gas), the temperature of the fluid increases. An equation

describing this phenomenon is:

𝑄 = 𝑀𝐶𝑝 △ 𝑇

Q is the amount of energy added (joules)

M is the mass of the fluid (kg)

Cp is the heat capacity of the fluid (joules/kg-°C)

ΔT is the change in temperature (°C)

A garage (24 ft x 24 ft x 10 ft) is illuminated by six 60-W incandescent bulbs. It is estimated that

90% of the energy consumed by an incandescent bulb is dissipated as heat. Question: If the bulbs

are on for 3 hours, how much would the temperature in the garage increase because of the light

bulbs? Assume that no energy is lost through the walls, floor, or ceiling of the garage.

Create a User Interface Worksheet like the one shown below, using the input/output units shown.

Wisely name the input/output cells so they can be easily referenced using the Range() method in

VBA.

Create a Sub procedure that does the following:

1. Declares all local variables using appropriate data types.

2. Reads the user inputs entered in the "Specified Information" input section of the worksheet,

using the cell range names that you defined, and stores the values in local variables.

3. Performs all necessary calculations.

4. Writes out the results to the "Calculated Information" section of the worksheet. Mind your

units!

Add user instructions and a printable "Run" button to the worksheet, for your user to use when

running your Sub procedure.

__MACOSX/._hw3.pdf

hw4.docx

· Read Chapra Chapter 11 (Structured Programming: Decisions)

· Complete Chapra Problems 11.1, 11.2, and 11.3 by hand (no code; turn in your paper only).  As described by the problem descriptions, show ALL steps in your evaluation (as shown in Figure 11.9).

· Complete Chapra Problem 11.4.  You will write a main Sub procedure that will read the input value of x from a named input cell of a User Interface Worksheet, and will write the output values of x and y to named output cells of the User Interface Worksheet.  Submit hardcopy of your worksheet and VBA code module, and submit your workbook Moodle.

__MACOSX/._hw4.docx

hw5.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 Wednesday, July 20 (see the last 2 slides of this week’s class notes for the

problem requirements).

__MACOSX/._hw5.pdf