Feb-07-2020, 06:44 PM
#I am taking an online python class for fun. I have read ahead and this is one of the questions that I
#received. I have no idea where to begin. Any help?
Make a bisection and secant method code to allow it to solve a multi-dimensional function (MD function).
We will use the function f1 below to test your methods.
def f1(var):
x,y,z = var
return np.cos(y+x**2) + z
The values for the variables that are to remain constant and the two initial guesses for the variable of interest should be provided in your new MD-root-finder method in two lists (one list for each guess and constant values). If you require the two guesses to straddle the root, be sure that is specified in your dock string, and check to make sure they do. If they do not, stop the program and tell the user. If you wish, you could also have the user input which of the three variables should be solved for, or you could ascertain that from comparing the input initial guess lists. All inputs must be in the function call parenthesis “()” for your new root-finder method. Include the function f1 from above in the same file as the solver.
1. Solve for x at y=2.5,z=0.2. There is a root at x=1.4181. See if your solver finds it.
2. Solve for y at x=1.4,z=0.2. There is a root at y=2.5510. See if your solver finds it. [/i][/b]
#received. I have no idea where to begin. Any help?
Make a bisection and secant method code to allow it to solve a multi-dimensional function (MD function).
We will use the function f1 below to test your methods.
def f1(var):
x,y,z = var
return np.cos(y+x**2) + z
The values for the variables that are to remain constant and the two initial guesses for the variable of interest should be provided in your new MD-root-finder method in two lists (one list for each guess and constant values). If you require the two guesses to straddle the root, be sure that is specified in your dock string, and check to make sure they do. If they do not, stop the program and tell the user. If you wish, you could also have the user input which of the three variables should be solved for, or you could ascertain that from comparing the input initial guess lists. All inputs must be in the function call parenthesis “()” for your new root-finder method. Include the function f1 from above in the same file as the solver.
1. Solve for x at y=2.5,z=0.2. There is a root at x=1.4181. See if your solver finds it.
2. Solve for y at x=1.4,z=0.2. There is a root at y=2.5510. See if your solver finds it. [/i][/b]