Lab 01
Lab 01
Exercise 1:
import math
f = math.factorial(num)
Exercise 2:
import numpy as np
import statistics
r = np.round(x, 7)
#I rounded to 7 decimal places to get the numbers to display properly in the text file
#When I looked for a solution online, they indicated this can fix it, and it did
print(*sort,sep='\n') #prints the sorted values, with each value on a new line
3. Exercise 3
import numpy as np
import matplotlib.pyplot as plt
y = 10 - whateveryouwant**2 + whateveryouwant**3/10
#The y function that the input gets applied to (and is later used for the plot)
def calculate_y(whateveryouwant):
#creates calculate_y as the function and whateveryouwant as the independent value(s)
y = 10 - whateveryouwant**2 + whateveryouwant**3/10
return y
x_values = x_create_values.tolist() #Converts the array into a list (since you asked for it as a
"list")
y_values = [] # create empty list to hold y dependent variables as they are calculated
plt.xlabel('x')
plt.ylabel('y')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x_values = array[:, 0]
y_values = array[:, 1] #These two lines split the x and y values into two new arrays
plt.figure(figsize=(8, 8)) #Creates the plot with uniform x and y to ensure equal scaling
plt.grid(True)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Points and Connecting Line')
plt.legend()
#The above adds a grid for clarity, labels, and a legend
plt.show()