% Problem: %Consider the following two formulas. %(a) A = x*y^2 - 5; %(b) B = (x+y)*pi %Now we require the sum of A and B is 500 and we know that 1 ? y ? 10, %please calculate the value of x which can maximize A*B. %solution y = [1:0.1:10]; % create y vector, within 1 and 10 with step 0.1 %sum of A and B is fixed 500 sum = 500; %sum = x*y^2 - 5 + (x+y)*pi % = x*(y^2 + pi) + y*pi %so, x = (sum - y.*pi) ./ (y.^2 + pi) %now we calculate the product product = (x.*y.^2 - 5).*((x+y).*pi) %remember product, as well as x and y, is a vector %now we find the max product %as before, z is the max value and k is the index [z, k] = max(product) %prepare the final result %format: x, y, max_product T = [x(k), y(k), product(k)]