Clear Filters
Clear Filters

How to find out all the possible values of x&y that make a function maximum?

3 views (last 30 days)
Say there is a function, f(x, y) = sin(3x) + sin(2y), how can I find out all the possible values(In a certain range) of x&y that maximize the function using fminsearch function?
And the results need to be displayed in the command lines.
I am a beginner at Matlab, I've tried using fminsearch function but it could only gave out one solution. Someone help me please.
  1 Comment
Torsten
Torsten on 26 Oct 2022
Do you know when sin(3*x) becomes 1 ?
Do you know when sin(2*y) becomes 1 ?
All pairs of these x-y-values are solutions.

Sign in to comment.

Answers (1)

Shubham
Shubham on 20 Mar 2024
Hi IvanC,
To find the maximum of a function using fminsearch in MATLAB, you actually need to search for the minimum of the negative of that function because fminsearch is designed to find the minimum value. However, finding all possible values within a certain range that maximize the function is a bit more complex because fminsearch typically converges to a local minimum (or in our case, a local maximum when we consider the negative of the function) based on the initial guess provided.
Given the periodic nature of your function, f(x, y) = sin(3x) + sin(2y), there will be multiple local maxima within any range that spans multiple periods of the sine function. fminsearch won't inherently find all these maxima; it will only find one, depending on the initial guess.
To systematically find multiple local maxima, you would need to run fminsearch multiple times with different initial guesses spread across your range of interest. However, this approach doesn't guarantee finding all maxima, especially in more complex landscapes, without a more sophisticated global optimization strategy. MATLAB's Global Optimization Toolbox offers functions like GlobalSearch and MultiStart that are more suited for this purpose.

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!