Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q4 of 15
SciPy - Advanced Optimization
What will be the output of the following code?
import numpy as np
from scipy.optimize import basinhopping

def func(x):
    return (x - 3)**2

result = basinhopping(func, 0)
print(round(result.fun, 2))
A0.0
B3.0
C9.0
D1.0
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function and start point

    The function is (x-3)^2, minimum at x=3 with value 0.
  2. Step 2: Basin-hopping finds global minimum

    Starting at 0, basin-hopping will find minimum at x=3, so function value is 0.
  3. Final Answer:

    0.0 -> Option A
  4. Quick Check:

    Minimum function value = 0.0 [OK]
Quick Trick: Basin-hopping finds global minimum value 0 here [OK]
Common Mistakes:
  • Confusing minimum location with value
  • Using start point as output
  • Misreading function formula

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes