필터 지우기
필터 지우기

Find minimum value of a function with 4 parameters

조회 수: 6 (최근 30일)
Axel Degrande
Axel Degrande 2022년 12월 6일
답변: Torsten 2022년 12월 6일
I have a grid of 10 by 10. I have to know the coordinates of the antenas in this grid, the antenas have to be as far away from each other. I know the best place will be x1=0, y1=0 and x2=10, y2=10 or x1=10, y1=10 and x2=0, y2=0 (the oposit). But I want Matlab to find that out. Right now I have a formula to calculate the distance between the two points. The problem is, I don't know how to enter 4 variables in fmincon because I have two x variables and two y variables.
As starting position I take [5 5 5 5] (the middel of the field) and for the left/ right bound i take [0 0], [10 10].
Thank you for helping me. If you have any more questions please ask.
% Antene 1: x1 = x(1), y1 = x(2)
% Antene 2: x2 = x(3), y2 = x(4)
distanceAntenes = @(x) -sqrt((x(3)-x(1))^2+(x(4)-x(2))^2);
[x1, y1, x2, y2] = fmincon(distanceAntenes, [5 5 5 5],[],[],[],[],[0 0],[10 10])

답변 (2개)

Walter Roberson
Walter Roberson 2022년 12월 6일
only change is your lower bound and upper bound need to be length 4
  댓글 수: 1
Axel Degrande
Axel Degrande 2022년 12월 6일
Thank you, this has worked, but only if I give a starting position of [0 0 8 8]. If I give it any thing else, it gives me wierd results. For Example [0 0 0 0].
afstandAntenes = @(x) -sqrt((x(3)-x(1))^2+(x(4)-x(2))^2);
[x1, y1, x2, y2] = fmincon(afstandAntenes, [0 0 8 8],[],[],[],[],[0 0 0 0],[10 10 10 10])

댓글을 달려면 로그인하십시오.


Torsten
Torsten 2022년 12월 6일
distanceAntenes = @(x) -sqrt((x(3)-x(1))^2+(x(4)-x(2))^2);
x = fmincon(distanceAntenes, [5 6 3 7],[],[],[],[],[0 0 0 0],[10 10 10 10])
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 1×4
10.0000 0.0000 0.0000 10.0000
distanceAntenes(x)
ans = -14.1421

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by