A wire of 3 m length is to be used to make a circile and a square. How should the wire be distributed between two shapes in order to minimize the sum of the enclosed areas?
조회 수: 3 (최근 30일)
이전 댓글 표시
Can anyone write matlab code of this question?
A wire of 3 m length is to be used to make a circile and a square. How should the wire be distributed between two shapes in order to minimize the sum of the enclosed areas?
댓글 수: 2
채택된 답변
Stephan
2018년 12월 16일
Hi,
your code returns the correct result. Here is another way to write the same in symbolic form:
syms l1 l2 % declare symbolic variables
A_quad = (l1/4)^2; % area of square expressed with l1
A_circ = (l2/pi)^2*pi/4; % areas of circle expressed with l2
A = A_quad + A_circ; % sum of areas
A = subs(A,l2,l1-3); % using the constraint that l1 + l2 = 3 to eliminate l2
A_diff = diff(A,l1) == 0; % calculate first derivative and set it equal to zero
A_min = double(diff(lhs(A_diff),l1)) % check 2. derivative --> if positive it is a minimum
res = solve(A_diff,l1) % solve for l1 (analytic expression)
sol_l1 = double(res) % get a numeric value for the solution above
This returns:
A_min =
0.2842
res =
12/(pi + 4)
sol_l1 =
1.6803
Since A_min is positive you know it is a minimum. You can also check the result numeric within 2 lines of code:
% Check numeric
fun = @(l)((l(1)/4)^2 + (l(2)/pi)^2*pi/4);
num_sol_l1 = fmincon(fun,[3 0],[],[],[1 1],3)
The result is:
num_sol_l1 =
1.6803 1.3197
Best regards
Stephan
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!