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

Practical 13

Uploaded by

ojobosolomon4
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Practical 13

Uploaded by

ojobosolomon4
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Practical 13/MSC/MTH/0628

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

Exponential function plot


18

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

10 5 Exponential function plot


18

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

plot for the functiont y = log(x+-5).*exp(x)


15

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

plot for the function y = log(x+-5).*exp(x)


50

-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

%To plot more than one function on the same graph


%example, Given
%y(x) = e x/4
%z(x) = x^4 within the interval 0<x<15
x = 5:0.8:15
y = exp(x/4)
z = x.^4
plot (x,y,x,z),title('The plot of y=e^(x/4) and x^4'),
legend ('e^x/4','x^4')

The Graph

10 4 The plot of y=e (x/4) and x 4


5
x
e /4
4.5 4
x
4

3.5

2.5

1.5

0.5

0
5 6 7 8 9 10 11 12 13 14 15
7. Modified code

%To plot more than one function on the same graph


%example, Given
%y(x) = e x/4
%z(x) = x^4 within the interval 0<x<15
x = 5:0.9:15
y = exp(x/4)
z = x.^5
plot (x,y,x,z),title('The plot of y=e^(x/4) and x^4'),
legend ('e^x/4','x^4')

The Graph

10 5 The plot of y=e (x/4) and x 4


8
x
e /4
7 4
x

0
5 6 7 8 9 10 11 12 13 14 15
8. Modified code

%To plot more than one function on the same graph


%example 2, Given
%y(x) = e x/7
%z(x) = x^7 within the interval 0<x<15
%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
with line specifiers'), legend ('e^x/4','x^2')

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

plot of y1 = sin x plot of y2 = cos t plot of y3 = e x


1 1 30

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

%Generate array of plot on a single figure


%example two
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
13. Modified code

%Generate array of plot on a single figure


%example three
x = -3:0.4:3
t = 0:0.05:10
y1 = cos(x)
y2 = sin (t)
y3 = exp(x.^3)
y4 = t.^4
subplot(3,3,1)
plot(x,y1),title('plot of y1 = cos x')
subplot(3,3,2)
plot(t,y2),title('plot of y2 = sin 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^4')
The Graph

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

You might also like