Given the twovariable formula Fxy2x23yx23y5x62 Write a MATLA
Given the two-variable formula: F(x,y)=-(2x^2-3y)-(x^2*3y-5x+6)^2
Write a MATLAB function which does the following:
1. Take as (2) inputs, the x and y vector of values defined by the domains: -3<=x<=3 with 40 elements -1<=y<=3,with 40 element 2. Generate (but do not display) a 2D array of f(x,y) evaluated for every combination of x and y values. 3. Inside the function, nest a second function that has x, y, and the array as its 3 inputs and no output. The nested fuction should create a surface plot of f(x,y) and, in a new figure, a filled contour plot with 20 levels and a colorbar. Make sure your plots are properly titled and annotated. 4. Back in the main function, use symbolics to find the derivative of f(x,y) with respect to y, and an indefinite integral of f(x,y) with respect to x. 5. The (3) outputs of the main function should be the absolute minimum value of the formula, the derivative of the formula, and the integral of the formula.
Solution
Solution :
%try running this code/funciton in your matlab
%*************************************funciton begins here*************************
function [abs_min ,df,in ] = func( x,y )
%arguments are :
%abs : absolute minima
%df : differential wrt x
%in : integral wrt x
%*******************************************************
 %1 Take as (2) inputs, the x and y vector of values defined by the domains:
 %-3<=x<=3 with 40 elements -1<=y<=3,with 40 element 2
 [X,Y] = meshgrid(x,y);
 %*******************************************************
%2. Generate (but do not display) a 2D array of f(x,y) evaluated for every
 %combination of x and y values
 F=-((2*X.^2)-(3*Y))-((((X.^2)*3.*Y)-(5.*X)+6).^2) ;
 %****************************************************************
  %3. Inside the function, nest a second function that has x, y, and the
 %array as its 3 inputs and no output. The nested fuction should create
 %a surface plot of f(x,y) and, in a new figure, a filled contour plot
 %with 20 levels and a colorbar. Make sure your plots are properly titled and annotated.
 %*********************************************************************
  nested(X,Y,F);
     function nested(X,Y,F)
         surf(X,Y,F);
         xlabel(\'X\');
          ylabel(\'Y\');
          zlabel(\'F(X,Y)\');
          title(\'Surface plot\')
      figure;
     [C,h]=contour(X,Y,F,20);
     clabel(C,h);
     title(\'contour plot\')
     colorbar ;
     end
 %**************************************************************
 %4 Back in the main function, use symbolics to find the derivative of f(x,y)
 %with respect to y, and an indefinite integral of f(x,y) with respect to x
 syms X   Y ;
 df = diff(-((2*X.^2)-(3*Y))-((((X.^2)*3.*Y)-(5.*X)+6).^2),X);
 in = int(-((2*X.^2)-(3*Y))-((((X.^2)*3.*Y)-(5.*X)+6).^2),X);
 %***************************************************************
  %5. The (3) outputs of the main function should be the absolute minimum
 %value of the formula, the derivative of the formula, and the integral of the formula.
 abs_min = min(min(F));
 %************************************************************************
end
%*****************************end here******************************


