Menu

[solved]-Wondering Somebody Could Help Understand Better Problem Need Solve Python Templates Cannot Q39025428

I was wondering if somebody could help me understand better thisproblem that I need to solve with Python. I have some templatesthat I cannot modify so I just need to use what I have. The firstpicture is the introduction and what I need to do. The secondpicture is the template that I need to use to finish the code.

3. ERROR For every n, we can think of the values (Xn, yn), which come either from Jacobis method 46 or the Gauss-Seidel meth

Problem to Python code

[] import numpy as np # Finds the error of the nth approximation of the solution to system (1) using the Gauss-Seidel method.

3. ERROR For every n, we can think of the values (Xn, yn), which come either from Jacobi’s method 46 or the Gauss-Seidel method, as being an approximation to the solution of system (1). We can 47 therefore measure how close our approximation is by computing the distance from the point 48 (In, yn) to the point (x_val,y_val). If a and b are two NumPy arrays then we can compute the distance between a and b by the 50 command np.linalg.norm (a-b) # a and b must be NumPy arrays here, and not lists. Remember that you will need to import NumPy in this notebook before you can use the 52 function np.linalg.norm or any of the other NumPy functions in this lab. Another thing you 53 may need to remember is how to convert lists to arrays. For example, if you have two lists 54 list1 and list2 and you want to find the distance between them (thinking of them as vectors), 55 you will need to cast them as NumPy arrays when plugging them into the np.linalg.norm 56 function as follows: 1 np.linalg.norm(np.array(list1)-np.array(list2)) Problem 8. Define a function gs1_error that accepts as input a non-negative integer n and outputs the error of the Gauss-Seidel approximation (Xn, Yn) to the solution of system (1). In other words, it should output the distance between the nth approximation (Xn, Yn) and the true value (x_val,y_val) of the solution to (1). To test your code, the output for gs1_error(3) should be 0.0001189275688300568. Create a graph that plots the error of the estimate (In, yn) for the first 50 values of n (i.e. for n = 0,1, …, 49). We will discuss more about creating plots in Lab 4. For now, just use the code provided in the lab notebook. [] import numpy as np # Finds the error of the nth approximation of the solution to system (1) using the Gauss-Seidel method. def gs1_error(n): error–1 # Put your code here which should correctly redefine the value of the variable error. We’ve already set up the return statement for you. # Don’t change anything in the definition or return statement. return error # The following code will construct your plot of gsl_error for you. You don’t need to change anything in this cell, simply execute it. # Consider this one a freebie. # Nate that you must have a function defined called gsl_errar from the previous problem in order for the plat to be created. # We first import matplotlib.pyplot: import matplotlib.pyplot as plt This command uses the function gal_error to create a new function vect_gsl_error which will accept Numby arrays of various sizes as input, # instead of just a single number. vect_gal_error-np.vectorize(gs1_error) # This creates a Numpy array of values of the form [0,1,2,…,48,49). The 1 in the function tells NumPy to count up by ones. n_vals=np.arange 0,50,1) # This creates the plot, and labels the axes. See if you can determine what each command is doing. plt.title, “Error of the Gauss-Seidel Method Applied to System 1′) plt.xlabal Number of iterations’ plt.ylabel(‘Error’) plt.plot(n_vals, vect_gsl_error(n_vals), ‘ro’} plt.show() Show transcribed image text 3. ERROR For every n, we can think of the values (Xn, yn), which come either from Jacobi’s method 46 or the Gauss-Seidel method, as being an approximation to the solution of system (1). We can 47 therefore measure how close our approximation is by computing the distance from the point 48 (In, yn) to the point (x_val,y_val). If a and b are two NumPy arrays then we can compute the distance between a and b by the 50 command np.linalg.norm (a-b) # a and b must be NumPy arrays here, and not lists. Remember that you will need to import NumPy in this notebook before you can use the 52 function np.linalg.norm or any of the other NumPy functions in this lab. Another thing you 53 may need to remember is how to convert lists to arrays. For example, if you have two lists 54 list1 and list2 and you want to find the distance between them (thinking of them as vectors), 55 you will need to cast them as NumPy arrays when plugging them into the np.linalg.norm 56 function as follows: 1 np.linalg.norm(np.array(list1)-np.array(list2)) Problem 8. Define a function gs1_error that accepts as input a non-negative integer n and outputs the error of the Gauss-Seidel approximation (Xn, Yn) to the solution of system (1). In other words, it should output the distance between the nth approximation (Xn, Yn) and the true value (x_val,y_val) of the solution to (1). To test your code, the output for gs1_error(3) should be 0.0001189275688300568. Create a graph that plots the error of the estimate (In, yn) for the first 50 values of n (i.e. for n = 0,1, …, 49). We will discuss more about creating plots in Lab 4. For now, just use the code provided in the lab notebook.
[] import numpy as np # Finds the error of the nth approximation of the solution to system (1) using the Gauss-Seidel method. def gs1_error(n): error–1 # Put your code here which should correctly redefine the value of the variable error. We’ve already set up the return statement for you. # Don’t change anything in the definition or return statement. return error # The following code will construct your plot of gsl_error for you. You don’t need to change anything in this cell, simply execute it. # Consider this one a freebie. # Nate that you must have a function defined called gsl_errar from the previous problem in order for the plat to be created. # We first import matplotlib.pyplot: import matplotlib.pyplot as plt This command uses the function gal_error to create a new function vect_gsl_error which will accept Numby arrays of various sizes as input, # instead of just a single number. vect_gal_error-np.vectorize(gs1_error) # This creates a Numpy array of values of the form [0,1,2,…,48,49). The 1 in the function tells NumPy to count up by ones. n_vals=np.arange 0,50,1) # This creates the plot, and labels the axes. See if you can determine what each command is doing. plt.title, “Error of the Gauss-Seidel Method Applied to System 1′) plt.xlabal Number of iterations’ plt.ylabel(‘Error’) plt.plot(n_vals, vect_gsl_error(n_vals), ‘ro’} plt.show()

Expert Answer


Answer to I was wondering if somebody could help me understand better this problem that I need to solve with Python. I have some t… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *