0
0
SciPydata~10 mins

Method selection (Nelder-Mead, BFGS, Powell) in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the minimize function from scipy.optimize.

SciPy
from scipy.optimize import [1]
Drag options to blanks, or click blank then click option'
Aminimize
Boptimize
Cmin
Dopt
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'optimize' instead of 'minimize'.
Using 'min' which is a built-in function, not from scipy.
2fill in blank
medium

Complete the code to define the function to minimize: f(x) = (x-3)^2.

SciPy
def func(x):
    return (x[1]3)**2
Drag options to blanks, or click blank then click option'
A+
B/
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' which changes the function.
Using '*' or '/' which are incorrect here.
3fill in blank
hard

Fix the error in the code to minimize the function using the Nelder-Mead method.

SciPy
result = minimize(func, x0=0, method=[1])
Drag options to blanks, or click blank then click option'
A'BFGS'
B'Gradient'
C'Nelder-Mead'
D'Powell'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'BFGS' or 'Powell' instead of 'Nelder-Mead'.
Using 'Gradient' which is not a valid method name.
4fill in blank
hard

Fill both blanks to minimize the function using the BFGS method starting at x=2.

SciPy
result = minimize(func, x0=[1], method=[2])
Drag options to blanks, or click blank then click option'
A2
B'BFGS'
C'Nelder-Mead'
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using x0=0 instead of 2.
Using method 'Nelder-Mead' instead of 'BFGS'.
5fill in blank
hard

Fill all three blanks to minimize the function using Powell method starting at x=1 and print the optimized value.

SciPy
result = minimize(func, x0=[1], method=[2])
print(result.[3])
Drag options to blanks, or click blank then click option'
A1
B'Powell'
Cx
Exopt
Fx0
Gxval
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names.
Trying to print result.xopt or other invalid attributes.