you are designing a rectangular page to contain 60 inch^2 of printing with a 4-inch marging at the top bottom and a 2-inch margin at each side.what overall dimensions will minimize the amount of paper used?

1 view (last 30 days)
%Solving problem 2
fprintf('Code for problem 2 \n')
area = 60;
syms 1 b;
1 == (60/(b-4)) + 8;
A = 1 * b;
A = diff(A, b) == 0;
[b1] = solve(A);
[11] = [(60/(b1(1)-4)) + 8, (60/(b1(2)-4)) + 8];
fprintf('Dimensions of page for minimum area is :\n')
if (11(1)<0)
fprintf('Length : %f\n', 11(2))
fprintf('Breadth : %f\n', b1(2))
elseif(11(1)>0 && 11(2)>0)
fprintf('Lenght1 : %f\n', 11(1))
fprintf('Breadth1 : %f\n', b1(1))
fprintf('Length2 : %f\n',11(2))
fprintf('Breadth2 : %f\n',b1(2)
else
fprintf('Length : %f\n', 11(1))
fprintf('Breadth: %f\n', b1(1))
end
and i am getting errors be like
'invalid eprssion when calling a fuction or indexing a variable,use parentheses otherwise,check for mismatched delimiters'

Answers (1)

Guillaume
Guillaume on 10 Aug 2019
While this is valid matlab:
1 == (60/(b-4)) + 8;
it doesn't do much. Without the semicolon at the end, it would just display whether the comparison is true or false. With the semicolon suppressing output, it simply doesn't do anything.
This, on the other hand:
[11] = [(60/(b1(1)-4)) + 8, (60/(b1(2)-4)) + 8];
attempts to assign the result of an expression to 11, which is meaningless, and indeed will result in an error. The expression on the left side of an = must be a variable (indexed or not).

Community Treasure Hunt

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

Start Hunting!