How can you maximize area of a rectangle given a total perimeter?

조회 수: 5 (최근 30일)
Lucas Ross
Lucas Ross 2016년 2월 10일
댓글: Guillaume 2016년 2월 10일
If you have 30 fence panels each with 1 meter width, how should you arrange them to maximize the area of the rectangle? Write a program that does this for you. And the panels cannot be broken, they have to stay whole.

채택된 답변

VIKAS
VIKAS 2016년 2월 10일
Try to make it a square, as square will have the maximum area for the given perimeter. If creating is not possible try to make the sides difference as minimum as possible. So as you mentioned 30 fence are available so the 7.5 would be the best but as we can not broke the fence i half then 7 fence at one side and 8 fence at other side will be the best option for this.
  댓글 수: 1
Lucas Ross
Lucas Ross 2016년 2월 10일
I have the dimensions figured out I just need help putting into a program. Thank you for the help

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

추가 답변 (1개)

Torsten
Torsten 2016년 2월 10일
max_area = 0.0;
for k=1:7
a=k;
b=15-k;
area = a*b;
if area > max_area
a_max = a;
b_max = b;
max_area = area;
end
end
Variables a_max and b_max give you the side lengths of the rectangle with maximum area.
Best wishes
Torsten.
  댓글 수: 1
Guillaume
Guillaume 2016년 2월 10일
The loop is a bit overkill:
num_panels = 30;
sides = 1:floor(num_panels/2);
area = sides.*(num_panels - 2*sides)/2;
[~, optimumlength] = max(area)

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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by