code1
code1
code1
clc
clear all
Close all
rv=[1 2 3 4 5] % row vector
cv=rv' % ' - Transpose
cv2=[1;2;3;4;5] % column vector
lrv=length(rv);
srv=size(rv);
A=[1 2;3 4]
dA=det(A)
rA=rank(A)
lA=tril(A)
uA=triu(A)
dA=diag(A)
Slicing a Matrix
Transpose operations
x=[1 2 3 4 5]
y=[2 2 2 3 3]
z1=x*y'
z2=x'*y
z3=x.*y
z4=x.^y
z5=x./y
A. Mathematical form:
Command Description
plot(y) Plots the columns of Y versus the index of each value
when Y is a real number. For complex Y, plot(Y) is
equivalent to plot(real(Y),imag(Y))
plot3(X1,Y1,Z1) Displays a three-dimensional plot of a set of data points
surf(Z) Creates a three-dimensional shaded surface from the z
components in matrix Z, using x = 1:n and
y = 1:m, where [m,n] = size(Z)
ezsurf(fun) Creates a graph of fun(x,y) using the surf function. fun is
plotted over the default domain:
-2π < x < 2π, -2π < y < 2π.
y = linspace(a,b,n) Generates a row vector y of n points linearly spaced
between and including a and b.
2
mesh(X,Y,Z) Draws a wireframe mesh with color determined by Z so
color is proportional to surface height
[X,Y] = meshgrid(x,y) Transforms the domain specified by vectors x and y into
arrays X and Y, which can be used to evaluate functions
of two variables and three-dimensional mesh/surface
plots.
subplot(m,n,p) Breaks the figure window into an m-by-n matrix of small
axes, selects the pth axes object for the current plot, and
returns the axes handle.
colormap(map) Sets the colormap to the matrix map. If any values in
map are outside the interval [0 1], you receive the error
Colormap must have values in [0, 1].
Prism Repeats the six colors red, orange, yellow, green, blue,
and violet
Flag Consists of the colors red, white, blue, and black. This
colormap completely changes color with each index
increment
hsv Varies the hue component of the hue-saturation-value
color model. The colors begin with red, pass through
yellow, green, cyan, blue, magenta, and return to red.
shading flat Controls the color shading of surface and patch graphics
objects.
PARAMETRIC PLOTTING
clc
clearall
close all
t = linspace(0, 2*pi,20);
x = 3+2*cos(t);
y = 4+2*sin(t);
plot(x,y,'k-*')
axis equal
xlabel('x(m)')
ylabel('y(m)')
title('graph of (x-1)^2+(y-3)^2=4')
legend('(x-1)^2+(y-3)^2=4')
OUTPUT
3
1. MULTIPLE PLOTS IN A FIGURE WINDOW (USING COMMAND
HOLD ON)
clc
clear all
close all
x = linspace(0,1)
plot(x,x.^2,'r*')
hold on
plot(x,sin(x),'g.')
plot(x,exp(x),'m+')
legend('x^2','sin(x)','exp(x)')
OUTPUT
x =
Columns 1 through 9
4
0 0.0101 0.0202 0.0303 0.0404 0.0505
0.0606 0.0707 0.0808
Columns 10 through 18
Columns 19 through 27
Columns 28 through 36
Columns 37 through 45
Columns 46 through 54
Columns 55 through 63
Columns 64 through 72
Columns 73 through 81
Columns 82 through 90
Columns 91 through 99
Column 100
1.0000
5
2. MULTIPLE GRAPHS IN A FIGURE WINDOW BY USING
SUBPLOT
clc
clear all
close 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')
6
3. GRAPH OF A CURVE THROUGH EZPLOT COMMAND
clc
clear all
symsx % Declaring the parameters as a symbolic object
f=sin(2*x)+cos(3*x)
figure(1)
ezplot(f)
figure(2)
ezplot(f,[0,3])
OUTPUT
f =
cos(3*x) + sin(2*x)
7
8