You are on page 1of 6

LAB ASSIGNMENT 2

NAME OF THE STUDENT: ANKIT KUMAR SINGH


REGISTRATION NUMBER: 21BCE1247
SLOT : L55 56
DATE :1 OCTOBER2021
NAME OF FACULTY :DR. G HANNAH
GRACE

PLOTTING GRAPHS FOR CURVES


AND SURFACES
COMMAND DESCRIPTION
Plot(y) Plots the column of Y versus the index of each value when Y is a
real number. For complex Y, plot(y) is equivalent toplot(real(Y),
imag(Y))

ezplot(fun) Plots the expression fun(x) over the default domain -


2pie<x<2pie,where fun(x) is an explicit function of only x.

ezplot(fun,[xmin,xmax] Plotsfun(x) over the domain:xmin<x<xmax

hold on Hold on retains the current plot and certain axes


properties so that subsequent graphing command
add to the existing graph.

hold off Holds off resets axes properties to their defaults


before drawing new plots. Hold off is the default.
legend plot two waves, and add a dashed zero line by calling
the yline function. Then create a legend, and exclude
the zero line by specifying its label as ''.

Ezsurf ezsurf(f) creates a graph of f(x,y), where f is a string


that represents a mathematical function of two
variables, such as x and y.

linspace The linspace function generates linearly spaced


vectors. It is similar to the colon operator ":", but
gives direct control over the number of points

title Each axes graphics object can have one title. The title


is located at the top and in the center of the axes.

title('string') outputs the string at the top and in the


center of the current axes.

syms The syms function creates a variable dynamically.


For example, the command syms x creates the
symbolic variable x and automatically assigns it to a
MATLAB variable with the same name.
Colormap A colormap is an m-by-3 matrix of real number
between 0.0 and 1.0. Each row is an RGB vector that
defines one color. The kth row of the colormap defines
the kth color , where map(k,: )=[r(k) g(k) b(k)
specifies the intensity of the red blue and green.
meshgrid [x, y]= meshgrid ( x, y) transform the domain
specified by vector x and y into array x and y , which
can be used to evaluate the function of two variables
and three dimensional surface plots.
surf Surf(X,Y,Z) creates a three- dimensional surface
plot, which has a solid edge colors and face colors.
The function plot the values in matrix Z as height
above a grid in the x-y plane defined by X and Y.
+,-,*,/ Matrix math operation
^, .^, Matrix and array power
==,<,>, <=,>= Relational operators
Array multiplication and division
.*, ./

+, . *, .x , s, d Markers
g, b, c color

Code-1
% Parametric plot of a circle with centre (3,4) and radius 2
clc
clear all
t= linspace(0,2*pi,100)
x= 3+2*cos(t)
y= 4+2*sin(t)
plot(x,y,"r-*")
axis equal
xlabel("x(m)")
ylabel("y(m)")
title("graph with centre (3,4) and radius 2")

output

Code 2
% Multiple plots in a figure window(using command hold on)
clc
clear all
x = linspace(0,1)
plot(x,x.^2,'r*')
hold on
plot(x,sin(x),'g.')
hold on
plot(x,exp(x),'m+')
legend('x^2','sin(x)','exp(x)')
hold off

output
Code3
% Multiple plot in the figure window (using without command hold on)
clc
clear all
x= linspace(0,1)
plot(x,x.^3,'r+',x,sin(x),'k-',x,exp(x),'g.')
legend('x^3','sinx','exp(x)')

output

CODE4
clc
clear all
x=0:0.1:2*pi;
subplot(2,2,1)
plot(x,sin(x))
subplot(2,2,2)
plot(x,cos(x),'r-*')
subplot(2,2,3)
plot(x,exp(-x),'go')
subplot(2,2,4)
plot(x,sin(3*x),'ms')

OUTPUT
CODE 5
%Graph of a curve through ezplot command
clc
clear all
syms x
f= sin(2*x)+cos(3*x)
figure (1)
ezplot(f)
figure(2)
ezplot(f,[0,3])

output

Code6
clc
clear all
syms x y
f= 2*(x*2+y*2)
ezsurf(f)
colormap cool
x=-1:.05:1;
y=-1:.05:1;
[x,y]= meshgrid(x,y);
z=x.*y.^2-x.^3
surf(x,y,z);

output

You might also like