How to find out all the possible values of x&y that make a function maximum?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Torsten
2022-10-26
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.
回答(1 个)
Shubham
2024-3-20
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!