本次CS代写的主要涉及如下领域: Python代写,北美程序代写,美国程序代写,Texas A&M University代写,ENGR 102-214代写

# ENGR 102-214 - Socolofsky

```
Engineering Lab I - Computation
Lab Assignment #01b
Writing your first programs: Assignment, print, and string formatting
```

Date due: 9/2/2019 at 3:00 p.m.

Return your solution based on the activities below by the date and time shown above. Please show all your work and follow the rules outlined in the course syllabus. The work for this part of the Lab assignment is expected to be done as homework individually. This lab assignment is adapted from the assignments created by the teaching team for ENGR 102.

In this assignment, you will gain practice using the Sypder IDE and in creating and running Python script files. You will also start using the Python=assignment operator to assign values to variables, accessing online documentation for Python modules, working with theprint()function to display results, and using string concatenation and formatting to control how output is displayed. Please complete each of the following two problems in separate Python script files. Remember to include the appropriate header block and use comments throughout each file to document what you are doing. When you are finished creating and testing your programs, please upload your solutions in eCampus to the assignment labeled “Lab Assignment 1b” under the “Week 01” folder in the “Content” section of the ENGR 102 module for Section 214. You should upload two separate Python script files for this assignment.

# 1. Program 1: Engineering Formulas

The purpose of writing this program is to familiarize yourself with some basic engineering equations and to provide practice writing a simple Python program that performs calculations and displays results. In the new Zachry Engineering Quad, you will find 50 different equations (etched in brick) relevant to various aspects of engineering. The equations referenced below appear among these equations. You may wish to find where each of them appears in the E-quad. For each of the five equations below, write code that will display the numerical result of using the equation with the specified inputs. Notice that the inputs have units associated with them and that properly interpreting the result of each equation requires understanding that the units associated with each input work together to produce the desired result. Please include comments in your code to describe what the code is doing in each section. Some of these comments should provide references (citations) to the resources you used to find each equation. Also, please use assignment statements and user-defined variables to make the calculations, then use a combination ofprint()statements to document the values and the units of the input used and of the calculated result. As an example, consider if you wanted to compute

```
the volume of a pyramid of base 2.5 units and height 4 units. You might have the following lines
in your program:
```

1 # Compute the volume of a pyramid. Use the equation given at 2 # https ://www.mathopenref.com/pyramidvolume.html 3 b = 2. 4 h = 4. 5 V = 1./3. * b**2 * h 6 7 print('\nThe volume of a pyramid of base {} units squared'.format(b)) 8 print(' and height {} units is:'.format(h)) 9 print('\n V = 1/3 b^2 h = {} units cubed'.format(V))

```
When you run this code, the output would be:
The volume of a pyramid of base 2.5 units squared
and height 4.0 units is:
```

```
V = 1/3 b^2 h = 8.333333333333332 units cubed
In the code example above, note the following:
```

- Lines 1 and 2 are comments that first, state the problem to be solved and second, provide citations to the references used for this block of code.
- Lines 3 and 4 assign values to the user-defined variablesbandh
- Line 5 computes the volume of the pyramid using the equation from the reference and the values stored in the user-defined variablesbandh, then the result is assigned to the user- defined variableV.
- Lines 7-9 print messages to the screen. The{}place-holder tells Python that you want to insert something there. The command.format()is a built-in method of strings, and the variable listed inside the()is the thing you want inserted at the position of{}. The character “n” in the sequence\nis called an “escape character,” and tells Python to print a new line.
- You could also write Lines 7-9 without using the.format()method using string concatena- tion (adding strings together using a+operator). To do this, you have to convert the numbers to strings using thestr()function, as follows: print('\nThe volume of a pyramid of base ' + str(b) + ' units squared') print(' and height ' + str(h) + ' units is:') print('\n V = 1/3 b^2 h = ' + str(V) + ' units cubed')
- Finally, you can also print multiple things with one print command by separating them with commas. Note, that Python will automatically insert spaces between each item. Hence, this last possibility to replace Lines 7-9 would read: print('\nThe volume of a pyramid of base', b, 'units squared') print(' and height', h, 'units is:') print('\n V = 1/3 b^2 h =', V, 'units cubed')

```
Since the print()function knows how to print numbers, you no longer need thestr()
function using this approach.
```

- The last thing to notice is that the result of the volume calculation prints a lot of decimal points. We can control this behavior using additional formating commands, but we will wait to learn these later.

Write a program that outputs each of the following items on subsequent lines. When standard functions are needed (e.g., the exponential function or trigonometric functions), you should use the functions available in the Pythonmathmodule.

- Ohms Lawstates that the current through a conductor between two points is directly pro- portional to the voltage across the two points. Calculate the voltage across a conductor with resistance 20 ohms and a current of 5 A.
- TheKinetic Energyof an object is the energy that it possesses due to its motion. The standard unit of kinetic energy is the joule. Calculate the kinetic energy of an object with mass 100 kg and velocity 2 m/s.
- TheReynolds Numberis an important dimensionless quantity in fluid mechanics that is used to predict flow patterns in different fluid flow situations. It is the ratio of inertial forces to viscous forces. Calculate the Reynolds number for a fluid with velocity 0.5 m/s, kinematic viscosity 1· 10 −^6 m^2 /s, and characteristic linear dimension 2.5 m.
- Arps equationis a mathematical model to forecast future production rates of oil and gas wells, given by

```
q(t) = qi
(1 +bDit)^1 /b
```

## (1)

```
whereq(t) is the production rate on dayt(barrels per day),qiis the initial production
rate (barrels per day),Diis the initial rate of decline of production (reciprocal days),bis a
dimensionless empirical constant, andtis the day number since production began (days).
Calculate the production of a well after 20 days if it had an initial production rate of 100 bbl/d,
an initial decline rate of 2 bbl/d, and an empirical constant of 0.8.
```

- TheMohr-Coulomb Failure Criterionrepresents the linear envelope that is obtained from a plot of the shear strength of a material versus the applied normal stress. More generally, the MohrCoulomb theory is a mathematical model that describes the response of brittle materials, like concrete or rubble piles, to shear stress as well as normal stress. Most of the classical engineering materials somehow follow this rule in at least a portion of their shear failure envelope. The Mohr-Coulomb criterion is represented by the following equation:

```
τ=σtan(φ) +c (2)
```

```
whereτis the shear stress (force per area),σis the normal stress (force per area), tan(φ) is
the slope of the failure envelop (length/length),φis the angle of internal friction, andcis the
```

```
cohersion (force per area). Calculate the shear stress when a normal stress of 20 lbf/in^2 is
applied to a material with cohesion 2 lbf/in^2 and angle of internal friction 35◦. You may refer
to the following link for more information:https://en.wikipedia.org/wiki/MohrCoulomb_
theory.
```

# 2. Program 2: Limits of Functions

```
You will encounter limits of functions in calculus and learn to work with them analytically. Writing
this program will introduce how limits can be calculated numerically and provide additional practice
creating computational Python programs.
Certain functions might be difficult to evaluate at particular values, where infinity or division
by 0 are involved, but could be understood by evaluating them at successive values that approach
0 or approach infinity. You are going to investigate three of these cases.
As you write your programs, remember that we do not want to copy and paste the same
calculation to multiple lines of our program. If we do, it becomes difficult to find and correct errors
when they occur. However, it is easy to edit one line of your program and re-run the program.
For each of the problems below, include lines in your program to print a message to the user that
describes what is going to be printed, evaluates the given function near the function limit, prints
your guess for the analytical solution to the limit equation, and prints a computed value at a point
that approaches the limit; be sure to tell the user what value of the limit variable is printed. For
example, you might have the code:
```

1 # Evaluate 5x / (x-2) at x = 2 2 print('This shows the evaluation of 5x / (x - 2) near the limit x = 2.') 3 print('My guess for the analytical solution is', 'infinity') 4 x = 1. 5 fx = 5 * x / (x - 2.) 6 print('The result evaluated at x = ', x, 'is', fx) 7 print()

```
The last empty print statement creates a blank line in preparation for printing the next set of
solutions. You can run this code successively with values ofxgiven by1.9,1.99,1.9999, etc. to
see how the result changes. If you try to run your program withx = 2., though, your code will
crash with a divide by zero error.
You should develop your guesses for the analytical solution by running your code multiple times.
Your guess will not be graded, though, only the calculations and print statements will be evaluated.
Do not forget to include the standard header block at the top of your program. To evaluate the
trigonometric functions, use the functions provided in the Pythonmathmodule.
```

- The function

```
f(x) =sin(x)
x
```

## (3)

```
is not defined at the valuex= 0 since sin(0) = 0 and, thus, we would be evaluating 0/0. Use
Python to estimate the limit asx→0.
```

- The function

```
g(x) =^1 −cos(x 2 x) (4)
```

```
is not defined at the valuex= 0 since cos(0) = 1 and, thus, we would be evaluating 0/0. Use
Python to estimate the limit asx→0.
```

- The function

```
h(x) =
```

```
(
1 +^1
x
```

```
)x
(5)
```

```
cannot be evaluated directly at infinity because infinity is not defined. Use Python to estimate
the limit asx→∞.
```