build-in optimization function for discrete date

4 views (last 30 days)
I have a bivariate function with 100 known coordinate points. I want to find which one of these 100 points minimizes the function value. Is there any built-in MATLAB function for this? The optimization problem is straightforward, and I don't need a complex optimization algorithm, just one with sufficiently low time complexity.
  2 Comments
子青
子青 on 27 Jan 2024
Moved: Star Strider on 5 Feb 2024
A = [0 258.623087554821
0.328661075749555 259.722049421362
0.657322151499110 260.821011287902
0.985983227248666 261.919973154442
1.31464430299822 263.018935020983
1.64330537874778 264.117896887523
1.97196645449733 265.216858754063
2.30062753024689 266.315820620604
2.62928860599644 267.414782487144
2.95794968174600 268.513744353684
3.28661075749555 269.612706220225
3.61527183324511 270.711668086765
3.94393290899466 271.810629953306
4.27259398474422 272.909591819846
4.60125506049377 274.008553686386
4.92991613624333 275.107515552927
5.25857721199288 276.206477419467
5.58723828774244 277.305439286007
5.91589936349199 278.404401152548
6.24456043924155 279.503363019088
6.57322151499110 280.602324885629
6.90188259074066 281.701286752169
7.23054366649022 282.800248618709
7.55920474223977 283.899210485250
7.88786581798933 284.998172351790
8.21652689373888 286.097134218331
8.54518796948844 287.196096084871
8.87384904523799 288.295057951411
9.20251012098755 289.394019817952
9.53117119673710 290.492981684492
9.85983227248666 291.591943551032
10.1884933482362 292.690905417573
10.5171544239858 293.789867284113
10.8458154997353 294.888829150653
11.1744765754849 295.987791017194
11.5031376512344 297.086752883734
11.8317987269840 298.185714750275
12.1604598027335 299.284676616815
12.4891208784831 300.383638483355
12.8177819542327 301.482600349896
13.1464430299822 302.581562216436
13.4751041057318 303.680524082977
13.8037651814813 304.779485949517
14.1324262572309 305.878447816057
14.4610873329804 306.977409682598
14.7897484087300 308.076371549138
15.1184094844795 309.175333415678
15.4470705602291 310.274295282219
15.7757316359787 311.373257148759
16.1043927117282 312.472219015299
16.4330537874778 313.571180881840];
r_starb = 16.6541049559731;
r_aft = 22.0243527832652;
r_fort = 37.0487055665303;
r_port = 12.8405787169798;
parameter_11_modified = @(x) power(2 * x(1) ./ ((1 + 1) * r_starb - (1 - 1) * r_port), 2) + ...
power(2 * x(2) ./ ((1 + 1) * r_fort - (1 - 1) * r_aft), 2) - 1;
[B_modified, fval_modified] = fminsearch(@(i) parameter_11_modified(A(i,:)), randi(size(A, 1), 1, 1));
Index in position 1 is invalid. Array indices must be positive integers or logical values.

Error in solution>@(i)parameter_11_modified(A(i,:)) (line 61)
[B_modified, fval_modified] = fminsearch(@(i) parameter_11_modified(A(i,:)), randi(size(A, 1), 1, 1));

Error in fminsearch (line 336)
fxr = funfcn(x,varargin{:});
The first column of A represents the x-coordinate, and the second column represents the y-coordinate. Substitute these points into the equation of parameter_11_modified and find the values that minimize parameter_11_modified.

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 24 Jan 2024
So you have the function values at 100 different points and you want to know for which of those points the function takes on its minimum value? Just call min on the array of function values with two outputs.
coords = rand(10, 2);
z = peaks(coords(:, 1), coords(:, 2));
% Just store the coordinates and value in a table for easy viewing
results = table(coords(:, 1), coords(:, 2), z, 'VariableNames', ["x coord", "y coord", "z"])
results = 10×3 table
x coord y coord z _______ ________ __________ 0.8518 0.6576 1.7875 0.2147 0.27487 -0.0015709 0.7616 0.88459 2.1235 0.40425 0.86036 1.856 0.98584 0.44561 2.4099 0.6305 0.067516 0.89791 0.64818 0.8218 1.7281 0.48698 0.93397 2.4026 0.81635 0.59551 1.6368 0.28119 0.79769 1.4355
[minimumValue, minimumLocation] = min(z)
minimumValue = -0.0016
minimumLocation = 2
To identify the coordinates where the minimum value in z is located:
coordinatesWhereMinimumOccurs = coords(minimumLocation, :)
coordinatesWhereMinimumOccurs = 1×2
0.2147 0.2749

Community Treasure Hunt

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

Start Hunting!