0% found this document useful (0 votes)
63 views

EE Comp MATLAB Activity 3

The document contains the results of MATLAB laboratory exercises on plotting 2-dimensional graphs. It includes plots of multiple functions using the figure command, logarithmic scale plots using subplot, multiple trigonometric equations on one graph using hold on, and polar plots of equations. Key results shown are plots of 3 functions individually in separate figures, logarithmic scale plots of an exponential function in 4 subplots, a graph with 4 trigonometric equations plotted together using hold on, and 3 polar plots of flower shapes.

Uploaded by

Reneboy Lambarte
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

EE Comp MATLAB Activity 3

The document contains the results of MATLAB laboratory exercises on plotting 2-dimensional graphs. It includes plots of multiple functions using the figure command, logarithmic scale plots using subplot, multiple trigonometric equations on one graph using hold on, and polar plots of equations. Key results shown are plots of 3 functions individually in separate figures, logarithmic scale plots of an exponential function in 4 subplots, a graph with 4 trigonometric equations plotted together using hold on, and 3 polar plots of flower shapes.

Uploaded by

Reneboy Lambarte
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

LYCEUM OF THE PHILIPPINES UNIVERSITY – LAGUNA

Km. 54, National Highway, Makiling, Calamba City, Laguna

COLLEGE OF ENGINEERING

ELEL40E – EE Computer Applications

MATLAB Laboratory Activity # 3


Plotting 2 – Dimensional Graphs

Lambarte, Reneboy M.
BSEE 4-1

Ronel V. Vidal, PECE


Instructor
I. Objectives:

1. To plot 2 – dimensional multiple graphs with MATLAB


2. To plot response curves in logarithmic scale
3. To plot polar equations with MATLAB

II. Laboratory Exercises

A. Figure Command
Look for 3 functions and plot them individually using the figure command.

B. Logarithmic Plots using the subplot command


Look for a function and plot it in linear, semilog x, semilog y, and log x & y
scale using the subplot command.

C. Hold on command
Look for 4 trigonometric equations (preferably sine and cosine) and plot them in
one graph using the hold on command.

D. Polar Plots
Look for 3 polar equations and plot them individually using the figure command.
A. The Figure Command

Consider the following functions:

a = 2cos (5t) + 2sin (t)


b = 5e-t
c = 3et + sin(t)

% Plotting Multiple Graphs with Figure command


>> t = [-8*pi:pi/100:8*pi];
>> a = 2*cos(5*t)+3*sin(5*t);
>> b = 5*exp(-t);
>> c = 3*exp(t)+sin(t);
>> figure(1), plot(t,a,'b','linewidth',2), grid on, title('Plot of 2cos(5^t)+3sin(5^t)'),
xlabel('time'),ylabel('Amplitude')
>> figure(2), plot(t,b,'g','linewidth',2), grid on,title('Plot of 5e^-^t'), xlabel('time'),
ylabel('Amplitude'),axis([-8*pi,8*pi,-3,3])
>> figure(3), plot(t,c,'y','linewidth',2), grid on,title('Plot of 3e^t+sin(t)'), xlabel('time'),
ylabel('Amplitude'),axis([-8*pi,8*pi,-4,4])

Plot of 2cos(5t)+3sin(5t)
4

1
Amplitude

-1

-2

-3

-4
-30 -20 -10 0 10 20 30
time

Figure 1
Plot of 5e-t
3

1
Amplitude

-1

-2

-3
-25 -20 -15 -10 -5 0 5 10 15 20 25
time

Figure 2

Plot of 3et+sin(t)
4

1
Amplitude

-1

-2

-3

-4
-25 -20 -15 -10 -5 0 5 10 15 20 25
time

Figure 3
B. Logarithmic Plots using the Subplot Command

>> % Plotting Linear and Logarithmic Scale Graphs


>> clear
>> n = 25;
>> t = [-8:0.001:8];
>> x = 16*exp(-n*t);
>> subplot(2,2,1); plot(t,x,'r','linewidth',2), grid on, title('Linear Plot'),
xlabel('Time,t'), ylabel('Amplitude,x'), axis([-1,2,0,10E-2]),
subplot(2,2,2); semilogx(t,x,'g','linewidth',2), grid on, title('Logarithmic X - Axis'),
xlabel('Time,t'), ylabel('Amplitude,x'), axis([-1,2,0,10E-2]),
subplot(2,2,3); semilogy(t,x,'m','linewidth',2), grid on, title('Logarithmic Y - Axis'),
xlabel('Time,t'), ylabel('Amplitude,x'),axis([-1,2,0,10E-2]),
subplot(2,2,4); loglog(t,x,'linewidth',2), grid on, title('Logarithmic Plot'),
xlabel('Time,t'), ylabel('Amplitude,x'),axis([-1,2,0,10E-2])

Linear Plot Logarithmic X - Axis


0.1 0.1
Amplitude,x

Amplitude,x

0.05 0.05

0 0
-1 0 1 2 0
10
Time,t Time,t
Logarithmic Y - Axis Logarithmic Plot
Amplitude,x

Amplitude,x

-50 -50
10 10

-1 0 1 2 0
10
Time,t Time,t
C. Hold on command

>> % Plotting Multiple Graphs with hold command


>> t = [-10:1/1000:10];
>> a = 7*cos(2*t);
>> b = 8*cos(9*t);
>> c = 10*sin(2*t);
>> d = 2*csc(2*t);
>> plot(t,a,'r','linewidth',2), grid on, hold on,
plot(t,b,'g--','linewidth',2),
plot(t,c,'m--','linewidth',2),
plot(t,d,'--','linewidth',2),
title('Multiple Graphs'), xlabel('time(s)'),
ylabel('Amplitude'),
legend('7cos(2t)','8cos(9t)','10sin(2t)','2csc(2t)'),
axis([-20,20,-21,21]),
hold off

Multiple Graphs
20
7cos(2t)
8cos(9t)
15
10sin(2t)
2csc(2t)
10

5
Amplitude

-5

-10

-15

-20
-20 -15 -10 -5 0 5 10 15 20
time(s)
D. Polar Plots

>> % Polar Plot of Basic Flower


>> clear
>> theta = 0:pi/100:4*pi;
>> r = 2 + 5*cos(20*theta);
>> polar(theta,r,'r'),title('Basic Flower 1')
>> s = 1 - sin(5*theta);
>> polar(theta,s,'g'),title('Basic Flower 2')
>> t = 1 + sin(25*theta);
>> polar(theta,t,'y'),title('Basic Flower 3')

Basic Flower 1
90 8
120 60
6

150 4 30

180 0

210 330

240 300
270

Figure 1. Basic Flower 1


Basic Flower 2
90 2
120 60
1.5

150 1 30

0.5

180 0

210 330

240 300
270

Figure 2. Basic Flower 2

Basic Flower 3
90 2
120 60
1.5

150 1 30

0.5

180 0

210 330

240 300
270

Figure 3. Basic Flower 3

You might also like