You are on page 1of 2

1.1: More than one trace can occupy a single plot.

For a pair of data sets (x1, y1) and (x2,


y2), both may be plotted by using the command plot(x1,y1,x2,y2). Plot sin and cos
versus (in degrees) from 0 to 720 degrees.

Setup: A very basic, unembellished routine that may be entered either in the command
window or as an m-file is:
a=0:10:720;
A=sind(a);
B=cosd(a);
plot(a,A,a,B)

But a better routine would include comments and more attention to the generated plot
(i.e. labeling of axes, a legend, etc.).

Solution: A more detailed and easier to follow m-file routine is as follows:

% MLP0101
%
% Plot sin(a) & cos(a) for 0 < a < 720 degrees
%
% 1/11/06 Wentworth
%
% Variables
% a angle in degrees
% A sind(a), accepts argument in degrees
% B cosd(a)

clc;clear;

% calculation
a=0:10:720; %uses 10 degree steps
A=sind(a);
B=cosd(a);

% generate plot
plot(a,A,'-k',a,B,'--b')
legend('sin(a)','cos(a)')
grid on
xlabel('angle a(degrees)')
ylabel('y')
title('Problem 1.1')

see Figure P0101

Written by Stuart M. Wentworth. Copyright John Wiley and Sons 2007


Problem 1.1
1
sin(a)
0.8 cos(a)

0.6

0.4

0.2

0
y

-0.2

-0.4

-0.6

-0.8

-1
0 100 200 300 400 500 600 700 800
angle a(degrees)

Figure P0101

Written by Stuart M. Wentworth. Copyright John Wiley and Sons 2007

You might also like