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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Busra Tabak
el 16 de Dic. de 2018
Comentada: madhan ravi
el 16 de Dic. de 2018
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 comentarios
Respuesta aceptada
Stephan
el 16 de Dic. de 2018
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
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Assumptions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!