Practical 13
Practical 13
1. Modified code
%Plot the function y = ex for the interval -2 < x <3; "Exponential function
plot"with the axis
%labelled 'x' and 'y = e^x',
%example
x = -2:0.6:3
y = exp(x)
plot (x,y),title ('Exponential function plot'), xlabel('x'),...
ylabel('y=e^x'), grid on
The Graph
16
14
12
10
y=e x
0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3
x
2. Modified code
%the plot of the function y = sin x over the interval 4<x<8 is carried out as
%follows
%example
a = 4:0.5:8
b = sin(a)
plot (a,b)
The Graph
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
4 4.5 5 5.5 6 6.5 7 7.5 8
3. Modified code
%plot the function ex for the interval -2<x<4; titled; "Exponential function
plot" with the axis
%labelled 'x' and 'y = e^x,
%example
x = -15:0.7:15
y = exp(x)
plot(x,y), title ('Exponential function plot'), xlabel('x axis'),...
ylabel('y=e^x'), grid on
The Graph
16
14
12
10
y=e x
0
-15 -10 -5 0 5 10 15
x axis
4. Modified code
%plot the function y = log(x+-5)ex for the interval -2<x<4; titled; "Log and
Exponential
%function plot "with the axis labelled 'x' and 'y=log(x+4) e^x,
%example
x = -2.5:0.1:4
y = log(x+-5).*exp(x)
plot(x,y),title ('plot for the function y = log(x+-5).*exp(x)'), xlabel('x
axis'),
ylabel ('y = log(x+-5) e^x'), grid on
The Graph
10
y = log(x+-5) ex
0
-3 -2 -1 0 1 2 3 4
x axis
5. Modified
%plot the function y = log(x+-5)ex for the interval -2<x<4; titled; "Log and
Exponential
%function plot "with the axis labelled 'x' and 'y=log(x+4) e^x,
%example
x = -2.5:0.1:6
y = log(x+-5).*exp(x)
plot(x,y),title ('plot for the function y = log(x+-5).*exp(x)'), xlabel('x
axis'),
ylabel ('y = log(x+-5) e^x'), grid on
The Graph
-50
-100
y = log(x+-5) ex
-150
-200
-250
-300
-350
-400
-2 -1 0 1 2 3 4 5 6
x axis
6. Modified code
The Graph
3.5
2.5
1.5
0.5
0
5 6 7 8 9 10 11 12 13 14 15
7. Modified code
The Graph
0
5 6 7 8 9 10 11 12 13 14 15
8. Modified code
The Graph
x 7
The
10 7 plot of functions y = e /7) and z=x with line specifiers
18
x
e /4
16 2
x
14
12
10
0
4 6 8 10 12 14 16
9. Modified code
%The above funcions are plotted using dotted and dashed lines to
%differentitae the plots
x = 4:0.5:15
y = exp(x/7)
z = x.^7
plot(x,y,'r:',x,z,'b-.'),title('The plot of functions y = e^x/7) and z=x^7
wthi line specifiers'), legend ('e^x/4','x^2')
The Graph
x 7
The
10 7 plot of functions y = e /7) and z=x wthi line specifiers
18
x
e /4
16 2
x
14
12
10
0
4 6 8 10 12 14 16
10.Modified code
%MATLAB by default gives limits to the graph according to the range of the
given variables. User can control where data appears in the axes by setting
axis limits. This is achieved by the use of the syntex:
%example
x = -8:0.06:7
y = sin(3*x)
plot(x,y),xlim([0 7]),ylim([-2 2])
The Graph
1.5
0.5
-0.5
-1
-1.5
-2
0 1 2 3 4 5 6 7
11.Modified code
%MATLAB by default gives limits to the graph according to the range of the
given variables. User can control where data appears in the axes by setting
axis limits. This is achieved by the use of the syntex:
%example
x = -8:0.06:7
y = sin(3*x)
plot(x,y),xlim([0 7]),ylim([-2 2])
%subplot
%Generate array of plot on a single figure
%example one
x = -3:0.4:3
t = 0:0.05:10
y1 = sin(x)
y2 = cos (t)
y3 = exp(x)
y4 = t.^2
subplot(3,3,1)
plot(x,y1),title('plot of y1 = sin x')
subplot(3,3,2)
plot(t,y2),title('plot of y2 = cos t')
subplot(3,3,3)
plot(x,y3),title('plot of y3 = e^x')
subplot(3,3,4)
plot(t,y4),title('plot of y4 = t^3')
The Graph
0.5 0.5
20
0 0
10
-0.5 -0.5
-1 -1 0
-3 -2 -1 0 1 2 3 0 2 4 6 8 10 -3 -2 -1 0 1 2 3
3
plot of y4 = t
100
50
0
0 2 4 6 8 10
12.Modified code
The Graph
1.5
0.5
-0.5
-1
-1.5
-2
0 1 2 3 4 5 6 7
13. Modified code
x
plot of y1 = cos x plot of y2 = sin t 10plot
11 of y3 = e
1 1 6
0.5 0.5
4
0 0
2
-0.5 -0.5
-1 -1 0
-5 0 5 0 5 10 -5 0 5
plot of y4 = t4
10000
5000
0
0 5 10
14. Modified code
%Data that are given explicitly as discrete data can be plotted directly by
%entering the vectors for the two variables and cell the plot function as
%usual. The two vectors must be of the same length.
x = [0.3, 0.5, 0.7, 0.9, 11.]
y = [3, 5, 7, 9, 11]
plot (x,y)
The Graph
11
10
3
0 2 4 6 8 10 12
15. Modified code
%Data that are given explicitly as discrete data can be plotted directly by
%entering the vectors for the two variables and cell the plot function as
%usual. The two vectors must be of the same length.
x = [0.5, 0.10, 0.15, 0.20, 0.25]
y = [11, 9, 7, 5, 3]
plot (x,y)
The Graph
11
10
3
0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
16. Modified code
%A given funtion plot can be overlaid with another plot function with the use
of hold on command
%example one
x = 0:0.02:20
y = exp(x/4)
plot (x,y,'r:')
hold on
z = x.^4
plot(x,z,'b--'),title('The plot of funtions y = e(x/4) and z = x^4 with line
specifiers'),legend('e^x/4','x^2')
The Graph
4
The
10 4 plot of funtions y = e(x/4) and z = x with line specifiers
16
x
e /4
14 2
x
12
10
0
0 2 4 6 8 10 12 14 16 18 20
17. Modified code
%A given funtion plot can be overlaid with another plot function with the use
of hold on command
%example one
x = 0:0.02:20
y = sin(x/4)
plot (x,y,'r:')
hold on
z = x.^4
plot(x,z,'b--'),title('The plot of funtions y = e(x/4) and z = x^4 with line
specifiers'),legend('e^x/4','x^2')
The Graph
4
The
10 4 plot of funtions y = e(x/4) and z = x with line specifiers
16
x
e /4
14 2
x
12
10
-2
0 2 4 6 8 10 12 14 16 18 20