Professional Documents
Culture Documents
% Definitions
% ti = initial time tf = final time dt = delta time
% Npts = number of points
%
% Example - ti, Npts, dt are known ... tf is unknown
ti=0;
Npts=10;
dt=2;
Basic plotting
Multiple things on a single set of axes
Axis labels and grid on
Subplots
Line/marker control
Legend
A line is shown
but only the
points (1,4)
(2,16) and
(3,36) exist
80 158
Think in terms of plotting y vs x. When we do max(y), we get
the max value of y (val) and the element number (pos) of the
max value in the array y. If we want the x value corresponding
to the max value of y, then we will want to evaluate x at the
element number for the max(y):
MAE 2100 Lecture 4 x(pos(1)) or x(pos(2))24
More on the max Command another example
t=[0:.6:2*pi];
y=sin(t);
figure,subplot(2,1,1),plot(t,y,'ro','MarkerSize
',8,'MarkerFaceColor','r'),grid on
xlabel('t'),ylabel('y')
subplot(2,1,2),plot(y,'ro','MarkerSize',8,'Mar
kerFaceColor','r'),grid on
xlabel('Element Number'),ylabel('y')
[mv,mp]=max(y)
subplot(2,1,2),hold
on,plot(mp,mv,'bs','MarkerSize',16,'LineWid
th',3)
subplot(2,1,1),hold
on,plot(t(mp),mv,'bs','MarkerSize',16,'Line
Width',3)
mv =
0.9738
mp =
4 MAE 2100 Lecture 4 25
More on the max Command abs and segments
ylen=length(y)
ymidpt=round(ylen/2)
[amv1,amp1]=max(abs(y(1:ymidpt)))
[amv2,amp2]=max(abs(y(ymidpt:end)))
subplot(2,1,2),hold on,
plot([amp1 amp2+ymidpt-1],[amv1 amv2],
'bs','MarkerSize',16,'LineWidth',3)
subplot(2,1,1),hold on,
plot([t(amp1) t(amp2+ymidpt-1)],[amv1 amv2],
'bs','MarkerSize',16,'LineWidth',3)
ylen = 11
ymidpt = 6
amv1 = 0.9738
amp1 = 4
amv2 = 0.9962
amp2 = 4
%% 3. Do matrix multiplication