Added files completed on 07/23
This commit is contained in:
parent
c7092bbaf8
commit
d20d15e03c
2 changed files with 215 additions and 0 deletions
123
A24_awparle.py
Normal file
123
A24_awparle.py
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
# !/usr/bin/env python3
|
||||
|
||||
import numpy as np
|
||||
|
||||
## A24_Question 1
|
||||
|
||||
# Adam Parler ENGR 1410-013 March 26, 2014
|
||||
#Problem Statement: Create a matrix of minimum values based on a users
|
||||
#input.
|
||||
|
||||
#Test Case 1
|
||||
y = np.array([[-2, 3, 5, 4],[7, 2, -10, 6],[18, 4, -2, 6], [3, 7, 5, -3]])
|
||||
# Expected outcome: Min values Row 1: -2 Row 2: -10 Row 3: -2 Row 4: 3
|
||||
#Max values Row 1: 5 Row 2: 6 Row 3: 18 Row 4: 7
|
||||
|
||||
# Test Case 2
|
||||
# y=[1; 2; 3; 4]
|
||||
#Expected outcome: This matrix does not have more than two columns.
|
||||
|
||||
# Variables
|
||||
# y=user inputed matrix
|
||||
# r=number of rows in y
|
||||
# c=number of columns in y
|
||||
# p=counter
|
||||
# MIN=matrix of numbers in odd numbered columns
|
||||
# MAX=matrix of numbers in even numbered columns
|
||||
# M=matrix of minimum and maximum values in each row
|
||||
# a=number of rows in M
|
||||
# b=number of columns in M
|
||||
|
||||
#Prompts user to input matrix
|
||||
#y=input('Input a matrix with at least two colums: ');
|
||||
[r,c]=y.shape
|
||||
|
||||
#checks to make sure it has 2 columns
|
||||
if c < 2:
|
||||
print('This matrix does not have more than two columns')
|
||||
sys.exit()
|
||||
|
||||
M = np.empty([r,2])
|
||||
#loops through each row
|
||||
for i in range(r):
|
||||
MIN = []
|
||||
MAX = []
|
||||
|
||||
#loops through the odd columns
|
||||
for j in range(0,c,2):
|
||||
MIN.append(y[i,j])
|
||||
|
||||
|
||||
#loops through the even columns
|
||||
for j in range(1,c,2):
|
||||
MAX.append(y[i,j])
|
||||
|
||||
#finds the minimun and maximum values
|
||||
M[i,0] = min(MIN)
|
||||
M[i,1] = max(MAX)
|
||||
|
||||
|
||||
[a,b]=M.shape
|
||||
#displays the output information
|
||||
print('The smallest value found when comparing the odd-numbered columns:')
|
||||
for k in range(a):
|
||||
print(f'Row {k+1:d} = {M[k,0]:.0f}')
|
||||
|
||||
print('The largest value found when comparing the even-numbered columns:')
|
||||
for h in range(a):
|
||||
print(f'Row {h+1:d} = {M[h,1]:.0f}')
|
||||
|
||||
|
||||
#####################################################################################
|
||||
|
||||
## A24_Question 2
|
||||
#Problem Statement: Allows a user to either select a previously entered
|
||||
#material or add a new one.
|
||||
|
||||
#Test Case 1
|
||||
c = 1
|
||||
#Expected outcome: The specific heat of Gold is 0.031 cal/(g deg c)=0.031 BTU/(lb_m deg F)
|
||||
|
||||
#Test Case 2
|
||||
# c=6
|
||||
# p=Uranium
|
||||
# Q=2.34
|
||||
#Expected outcome: The specific heat of Uranium is 2.340 cal/(g deg c)=2.332 BTU/(lb_m deg F)
|
||||
|
||||
#Assumptions
|
||||
# 1 joule=9.48x10^-4 BTU
|
||||
# 1 joule=.239 cal
|
||||
# 1 kg=2.205 lb_m
|
||||
# 1 kg=1000 grams
|
||||
# change of 1 degree C=change of 1.8 deg F
|
||||
#Converts BTU's to calories
|
||||
E = 1/.239*(9.48*10**-4)/1; #cal*J/cal*BTU/J [BTU-->J-->cal]
|
||||
|
||||
#Converts grams to pound-mass
|
||||
M = 1/1000*2.205/1; #g*kg/g*lb_m/kg [g-->kg-->lb_m]
|
||||
|
||||
#Convets change in deg C to change in deg F
|
||||
T = 1.8/1; #deg C*(change in deg F)/(change in deg C) [(deg C)*(deg F)/(deg C)
|
||||
|
||||
#Cell array of pre-determined data
|
||||
MAT = [['Aluminum', 0.22], ['Calcium', 0.22],['Gold', 0.031], ['Silicon', 0.17], ['Zinc', 0.093]]
|
||||
#c=menu('Choose a metal',MAT{:,1},'Enter a new metal');
|
||||
|
||||
#Checks to see if the user selected new metal
|
||||
if c >= len(MAT):
|
||||
pass
|
||||
#input new metal information
|
||||
#p=input('Enter material name: ','s');
|
||||
#q=input('Enter specific heat: (cal/(g deg c) ');
|
||||
else:
|
||||
#Pulles previously stored values
|
||||
p = MAT[c][0]
|
||||
q = MAT[c][1]
|
||||
|
||||
|
||||
#converts cal/(g deg C) to BTU/(lb_m deg F)
|
||||
g=q*E/(M*T);
|
||||
|
||||
#prints the results on the screen
|
||||
print(f'The specific heat of {p} is {q:.3f} cal/(g deg C) = {g:.3f} BTU/(lb_m deg F).')
|
||||
|
||||
92
A25_awparle.py
Normal file
92
A25_awparle.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
# !/usr/bin/env python3
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Adam Parler ENGR 1410-013 March 27, 2014
|
||||
#Problem Statement: This program classifies plasma and displays the result
|
||||
#on a graph.
|
||||
|
||||
#Test Case 1
|
||||
D = -8;
|
||||
T = 2.5;
|
||||
# Expected outcome: Phase=Molecular Fluid
|
||||
|
||||
#Test Case 2
|
||||
# D=-6;
|
||||
# T=5;
|
||||
# Expected outcome: Phase=Plasma
|
||||
|
||||
#Test Case 3
|
||||
# D=1.5;
|
||||
# T=3;
|
||||
# Expected outcome: Phase=Metallic Fluid
|
||||
|
||||
#Variables
|
||||
# D=Density (g/cc)
|
||||
# T=temperature (K)
|
||||
# CLASS=phase classification
|
||||
# DATA=all division data
|
||||
# X=x values for phase division
|
||||
# Y=y values for phase division
|
||||
# temp=temporary polyfit values
|
||||
# Div=values of polyfitted lines
|
||||
|
||||
DATA = np.array([[-10, 0, 3.3, 3.9], [0, 2, 3.9, 5.6], [0, 0, 2, 3.9]])
|
||||
|
||||
[r,c] = DATA.shape;
|
||||
|
||||
Div = np.empty([r-1,2])
|
||||
X = np.empty(2)
|
||||
Y = np.empty(2)
|
||||
for i in range(r-1):
|
||||
X[0] = DATA[i,0]
|
||||
X[1] = DATA[i,1]
|
||||
Y[0] = DATA[i,2]
|
||||
Y[1] = DATA[i,3]
|
||||
temp = np.polyfit(X,Y,1)
|
||||
Div[i,:] = temp
|
||||
|
||||
|
||||
# D=input('Enter log of density (g/cc): ');
|
||||
# T=input('Enter log of temperature (K): ');
|
||||
|
||||
if D <= DATA[r-1,0]:
|
||||
if T <= Div[0,0]*D+Div[0,1]:
|
||||
CLASS='Molecular Fluid'
|
||||
else:
|
||||
CLASS='Plasma';
|
||||
|
||||
else:
|
||||
if T <= Div[1,0]*D+Div[1,1]:
|
||||
CLASS='Metallic Fluid'
|
||||
else:
|
||||
CLASS='Plasma'
|
||||
|
||||
|
||||
|
||||
print(f'For the log density {D:.1f} and log temperature {T:.1f}, the phase is {CLASS}.')
|
||||
|
||||
plt.figure()
|
||||
plt.axis([-10, 2, 2, 6])
|
||||
plt.plot(D,T,'.r', markersize=10)
|
||||
plt.text(-6,2.8, 'Molecular Fluid')
|
||||
plt.text(-6, 4.5, 'Plasma')
|
||||
plt.text(.3,2.3, 'Metallic Fluid')
|
||||
plt.text(D+0.125, T-0.05, '<--Your point')
|
||||
|
||||
for i in range(r):
|
||||
X[0] = DATA[i,0];
|
||||
X[1] = DATA[i,1];
|
||||
Y[0] = DATA[i,2];
|
||||
Y[1] = DATA[i,3];
|
||||
plt.plot(X,Y,'-k')
|
||||
|
||||
plt.xlabel('Log Density ($\\rho$) [g/cc]')
|
||||
plt.ylabel('Log Temperature (T) [K]')
|
||||
plt.xticks(range(-10,3,2))
|
||||
plt.yticks(range(2,7))
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue