matlab2
DESCRIPTION
Matlab Tutorial 2TRANSCRIPT
Plot routines >> clear >> x=[1:0.01:2]; >> y=cos(tan(x))-tan(sin(x)); >> plot(x,y,'LineWidth',2,'color','m') results in the following plot (color magenta)
1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2-3
-2.5
-2
-1.5
-1
-0.5
The plot could be changed to >> plot(x,y,'LineWidth',2,'color','r') >> xlabel('frequency','FontSize',16) >> ylabel('amplitude','FontSize',16) >> title('TUNER PERFORMANCE') >> yielding
1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2-3
-2.5
-2
-1.5
-1
-0.5
frequency
ampl
itude
TUNER PERFORMANCE
Plotting with fplot. This is an intelligent plot function which provides more detail. >> x=1:0.01:2; >> f= 'cos(tan(x))-tan(sin(x))'; ← function is entered as a string >> fplot(f,[1 2]) ← The array pins down [xmin xmax] >>
1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2-3
-2.5
-2
-1.5
-1
-0.5
Polar plots >> t = 0:.01:2*pi; >> polar(t,sin(2*t).*cos(2*t),'--b')
0.1
0.2
0.3
0.4
0.5
30
210
60
240
90
270
120
300
150
330
180 0
Plotting complex functions. >> z=0.1+0.9i; >> n=0:01:10; >> y=z.^n+z; >> x1=imag(y); >> x2=real(y); >> plot(x2,x1)
-0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 1.20
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
>> x=-1:0.01:1; >> y1=3+exp(-x).*sin(3*x); >> y2=4+exp(-x).*cos(6*x); >> plot((0.1+0.9i).^[0:.01:10]) >> hold on ← Hold on to current frame >> plot(y1,y2) ← Plot this on the frozen frame >> gtext('y2 versus y1'), gtext('Imag(z) versus Real(z)') >> plot((0.1+0.9i).^[0:.01:10]) >> hold on >> plot(y1,y2) >> gtext('y2 versus y1'), gtext('Imag(z) versus Real(z)') >> hold off ← Release current frame
-1 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 4-1
0
1
2
3
4
5
6
7
y2 versus y1
Imag(z) versus Real(z)
>> tau=0.34; >> omega=1200; >> y=3.4*exp(-x/tau).*sin(omega*x); >> plot(x,y) >> hold on >> title('3.4e^(-x/\tau)sin(\omega x)') >> title('3.4e^{-x/\tau)}sin(\omega x)') >> title('3.4e^{-x/\tau}sin(\omega x)') >> title('3.4e^{-x/\tau}sin(\omega x)','FontSize',16) >> >>
1 2 3 4 5 6 7 8 9 10-0.04
-0.03
-0.02
-0.01
0
0.01
0.02
0.03
0.043.4e-x/τsin(ω x)
>> x=linspace(0,10*pi,100); >> y=exp(-0.1*x).*sin(x); >> plot(x,y) >> hold on >> plot(x,-exp(-0.1*x)); >> plot(x,exp(-0.1*x)); >> hold off >>
0 5 10 15 20 25 30 35-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
>> clear %drawing 3-d graphs and surfaces
>> [X Y]=meshgrid(-4:0.5:4,-1:0.1:1); ← an attempt to 3-d >> mesh(sin(X).*cos(Y)) >>
020
4060
80100
0
10
20
30-1
-0.5
0
0.5
1
With this change >> mesh(sin(X+Y).*cos(X-Y)) >>
020
4060
80100
0
10
20
30-1
-0.5
0
0.5
1
>> x=-0.5:0.005:0.5; >> y=x; >> [X Y]=meshgrid(x,y); >> mesh(X.^2+Y.^2) >>
050
100150
200250
0
100
200
3000
0.1
0.2
0.3
0.4
0.5
>> mesh(X.^2-Y.^2) >>
050
100150
200250
0
100
200
300-0.4
-0.2
0
0.2
0.4
>> x=-3:0.25:3; >> y=-3:0.25:3; >> [X Y] =meshgrid(x,y); >> Z=X.*exp(-X.^2+-Y.^2); >> s1=surf(X,Y,Z); >>
-4-2
02
4
-4
-2
0
2
4-0.5
0
0.5