How to use optimization in matlab?

조회 수: 2 (최근 30일)
BioZ
BioZ 2021년 11월 17일
답변: Alamanda Ponappa Poovaya 2021년 11월 24일
Greetings everyone, I am new to Global Optimization Toolbox.
Could someone explain to me please, I have the following simple code, which represents a square with side A and B.
Basically I am just trying to find value of x which would maximize my V (Volume).
How would I do that with an optimization toolbox? Any help would be much appreciated.
(I have Global Optimization Toolbox and Optimization Toolbox)
x = 0.2 %Optimization Variable <---
Lt = 10; %Total Perimeter Length
A = Lt*x % Side A
B = Lt-A % Side B
V = A*B %Volume (We want to maximize Volume)
rL = A+B

채택된 답변

Alamanda Ponappa Poovaya
Alamanda Ponappa Poovaya 2021년 11월 24일
Hi,
It appears you want to find the maximum area of a rectangle with sides A and B, such that A + B = Lt. This would assume that Lt is the semi perimeter of the shape. Regardless, this will not effect the Optimization variable x, but you may want to modify the code below, as if Lt is the perimeter, A = (Lt*x)/2 and B = Lt/2 - A
% range of x - from 0 to 1, as sides can have
x1 = 0;
x2 = 1;
%Semi perimeter = 10
Lt = 10;
%x is optimization variable
[x_max , val] = fminbnd(@(x) -(Lt*x)*(Lt-Lt*x),x1,x2);
%val is minimum
val = -val;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Direct Search에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by