Reference no: EM132793822
Question 1: Write a Python program to find the transpose of a matrix (i.e, AT), where the column vectors of AT are the row vectors of the original matrix A.
a. Define a function that meets the following specifications:
def TransposeMatrix(AMatrix):
AMatrix is a matrix of dimension m columns by n rows. Note that n≠m generally.
The function should return two values: AT The transpose of AMatrix and a tuple with the ordered pair of (number rows, number cols) of AT.
b. Define a function that meets the following specifications:
def main():
AM=[ [1, -5, 3, -7],
[2, 5, 11, -2],
[13, -1, 0, 4]]
The main function should call the function TransposeMatrix and output to the screen/console the following formatted output:
Transpose of the matrix is:
[[1, 2, 13]
[-5, 5, -1]
[3, 11, 0]
[-7, -2, 4]]
The size of the transpose is: (4 x 3)
Note: Your program should call the function main()when run. We will grade the problem with this exact matrix first and then change the matrix (including its size) to test your program.
Question 2: Stirling's approximation is used to estimate the value of natural logarithms of factorials of large numbers. The mathematical formula is:
a. Write a function that meets the following specifications:
def Stirling(N):
N is a positive integer.
The function should return both the estimated value of ln(N!) and the percent error in the estimation based on the formula: error=1-[nln(n)-n]/ln(N!)
b. Write a function that meets the following specifications:
def main():
Print lines of formatted output to the screen/console in the following format:
ln(500!) = 2605.3 (error = 0.15%)
Notes:
Output a similar formatted line only when error drops below values of 15%, 10%, 5%, 1%
You can calculate the natural logarithm of a function with log()from the math module.
You can calculate the factorial of an integer with factorial() from the math module.
Question 3: A pipe-flow fluids problem:
Oil with a density (ρ=950 kg/m3) and kinematic viscosity (ν=2×10-5m2/s) flows through a 30-cm-diameter (d=0.3m) pipe that is 100 m long with a head loss of hf = 8 m. The roughness ratio of the pipe is (?/d=0.0002) and we can assume the flow is turbulent. Find the average velocity (V) and flow rate (Q=V⋅A) for the oil. g=9.81 m/s2
We can calculate the head loss using the Darcy friction factor as:
where, the friction factor is given by:
where,
a. Write a function def Reynolds(V,nu,d): to calculate Reynolds number
b. Write a function def FrictionFactor(relrough, Re): to calculate the friction factor
c. Write a function def AvgVel(nu, dia, length): to calculate the average velocity of the oil
d. Write a function def main(): to call AvgVel with the appropriate parameters and print to the screen the average oil velocity and volumetric flow rate (with units).
e. Finally, in your main function, determine the diameter of pipe necessary for a head loss of only 6m in a 100m long pipe, keeping viscosity and flow rate constant.
Notes: The velocity V is unknown in parts a., b., and c as are the friction factor and Reynolds numbers. You will likely need to use your secant method to iteratively find the solution. According to the Moody diagram for friction factors, 0.008<f<~0.03 in the turbulent range. F.Y.I., V = 4.84 m/s for part d.
Attachment:- Python program.rar