Write a MATLAB code to plot a contour graph of f(x, y) = x^2 + y^2 for −2 ≤ x ≤ 2 and −3 ≤ y ≤ 3. Use the interval of 0.1 in the grid.
clc;clear
all
x=-2:0.1:2;
%creating a x vector with 0.1 space
y=-3:0.1:3;
%creating a y vector with 0.1 space
[X
Y]=meshgrid(x,y); % this gives meshgrid for the
contour plot
A=X.^2+Y.^2;
%Assigning the Value of f(X,Y) to A
contour(X,Y,A) %gives the
contour plot
xlabel('X');ylabel('Y');alabel('A')
%attaching labels to the axis
title('Contour plot
f(x,y)=x^{2}+y^{2}')
Get Answers For Free
Most questions answered within 1 hours.