Question: i need help at jupyter/python i did the 1 and 2 i only need help at 4 and 5 you can change the initial code
i need help at jupyter/python i did the 1 and 2 i only need help at 4 and 5 you can change the initial code




![L = 10 # m x_term = [0,0.1,0.2,0.3,0.4] numbers = list() for](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f465d999a6b_88966f465d93b3e1.jpg)
mport numpy as np import matplotlib.pyplot as plt q = 500 # N/m E = 200e9 # Pa I = 1e-4 # m^4 L = 10 # m x_term = [0,0.1,0.2,0.3,0.4] numbers = list() for x in x_term: y = (-q*x**2) / (24*E*I) * (x**2 - 4*L*x + 6*L**2) numbers.append([x,y]) # writing to the file with open('deflections.txt', 'w') as f: for item in numbers: f.write("%s " % item) # collecting all the x and y respectively x = np.array([numbers[0][0], numbers[1][0], numbers[2][0], numbers[3][0],numbers[4][0]]) y = np.array([numbers[0][1], numbers[1][1], numbers[2][1], numbers[3][1],numbers[4][1]]) # fitting the polynomial line1 = np.polyfit(x, y, 1) # oder 1 line2 = np.polyfit(x, y, 2) # order 2 line3 = np.polyfit(x, y, 3) # order 3 line4 = np.polyfit(x, y, 4) # order 4 # collecting all the coefficients coeff = list() coeff.append([item for item in line1]) coeff.append([item for item in line2]) coeff.append([item for item in line3]) coeff.append([item for item in line4]) # writing to the file with open('coefficients.txt', 'w') as f: for item in coeff: f.write("%s " % item)Q1: Deformation of a Cantilever Beam - 35 pts Cantilever beams are common structural elements. Given a cantilever beam of length L with a uniform distributed load q (Fig. a), the deflection of the cantilever beam along its length (Fig. b) is given by the following equation (x, is the distance from the fixed end): y(x) = 9x2 2 - 4Lx +612) 24E1 a) Cantilever beam 9 L b) Deflection profile Using Numpy and MatPlotLib solve the following questions 1) Given that the cantilever is L =10 m long, with modulus of elasticity E =200 10 Pa, area moment of inertia of cross section 1 =10* m, and the distributed load q =500 N/m find the deflection profile of the beam, y(x), by using Numpy. y(x) should be a numpy array corresponding to the deflection at distance x from the fixed end. Write the deflection profile y(x) as a function the distance x to a file in csv format, such that each line contains the distances and deflection values as follows: 2.0, -0.0 9.10101010101010102, -6.334066666242626e-06 0.20202020202020204, -2.5165799581727052-05 9.30303030303030304, -5.624145003475499e-05 0.4040404040404041, -9.930987186451741e-05 2.5050505050505051, -0.00015412252146109444 The file should be named as "deflections.txt" 2) By using Numpy function polyfit, fit polynomials of degree 1 upto 4 (i.e. 4 separate curve fits). Write the coefficients of the polynomial fits to a file name "coefficients.txt. The file should contain 4 lines, with each line displaying the coefficients separated by commas. No other information should be written to the file. Sample output -0.6033270627146889786, 0.804103712847505999 -0.60017901477497437072, -8.061536914964945267, 0.6011562764321039176 2.0833333333333346e-05, -0.0004915147749743705, -0.00029318558358962585, 0.000139956858659028 02 -1.6416666666666616-66 4.1666666666666415e-85, -6.0006249999999999978, -4.3157813326681686e-18, 7.632783294297952-18 4) Plot the results from the analytical solution for the deformation profile (x, y(x)), and the polynomial fits of order 1 upto 4. The plot should be formatted as follows: Deflection profile for the cantilever beam 0.005 Exact y(x) 0.000 Poly. Ord. 1 Poly. Ord. 2 -0.005 Poly. Ord. 3 Poly. Ord. 4 -0.010 y (m) -0.015 -0.020 -0.025 -0.030 6 10 x (m) Note that the exact solution is not visible, since the 4th order polynomial exactly matches the analytical result. 5) Plot the residuals for each polynomial fit. i.e. y'(x)-y(x), where y'(x) is the result obtained from the polynomial fit and y(x) is the analytical solution. Confirm that the 4th order polynomial yields an exact fit. Residuals from the polynomial fit 0.004 Poly. Ord. 1 Poly. Ord. 2 0.003 Poly. Ord. 3 Poly. Ord. 4 0.002 y'-y (m) 0.001 0.000 -0.001 8 10 x (m) You should submit only the cantilever.ipynb file. When executed the file should produce the outputs: 1) deflections.txt file, 2) coefficients.txt file, 3) Plot for the deformation profile as a png file named as deformation.png, 4) Plot for the residuals as a png file named residuals.png. In [1]: import numpy as np import matplotlib.pyplot as plt In [1]: q = 500 # N/m E = 200e9 # Pa I = le-4 # m^4 L = 10 #m x_term = [0,0.1,0.2,0.3,0.4] numbers = list() for x in x_term: y = (-q*x** 2) / (24*E*I) * (***2 - 4*L*x + 6*L**2) numbers.append([x,y]) # writing to the file with open('deflections.txt', 'w') as f: for item in numbers: f.write("%s " % item) In [2]: # collecting all the x and y respectively x = np.array([numbers[0][0], numbers [1][0], numbers [2][0], numbers[3][0], numbers[4][0]]) y = np.array([numbers[0][1], numbers [1][1], numbers [2][1], numbers [3][1], numbers[4][1]]) # fitting the polynomial line1 = np.polyfit(x, y, 1) # oder 1 line2 = np.polyfit(x, y, 2) # order 2 line3 = np.polyfit(x, y, 3) # order 3 line4 = np.polyfit(x, y, 4) # order 4 In [2]: # collecting all the x and y respectively x = np.array([numbers[0][0], numbers [1][0], numbers [2][0], numbers[3][0], numbers[4][0]]) y = np.array([numbers[0][1], numbers [1][1], numbers [2][1], numbers[3][1], numbers[4][1]]) # fitting the polynomial line1 = np.polyfit(x, y, 1) line2 = np.polyfit(x, y, 2) line3 = np.polyfit(x, y, 3) line4 = np.polyfit(x, y, 4) # oder 1 # order 2 # order 3 # order 4 # collecting all the coefficients coeff = list() coeff.append([item for item in line1]) coeff.append([item for item in line2]) coeff.append([item for item in line3]) coeff.append([item for item in line4]) # writing to the file with open('coefficients.txt', 'w') as f: for item in coeff: f.write("%s " % item) In [3]: #file=op #plt. savefig('deformation.png', dpi=300) In [ ]: #plt. savefig('residuals.png', dpi=300)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
