Vous êtes sur la page 1sur 5

Monday, January 23, 2017 Page |

Experiment 2: Generating Even, Odd, Shifting and Scaling Plots BT15ECE022

GENERATING EVEN, ODD, SHIFTING AND SCALING PLOTS

Objective
To generate programs on MATLAB to find the even and odd plots, and to shift and scale the
given discrete and continuous plots.

Mathematical Functions
()+()
1. Even Function: y(t) = 2
()()
2. Odd Function: y(t) = 2

Code

1. To generate Even and Odd Plots for a User Defined Discrete Plot.
Also Shift and Scale the Plot.
clc;
clear all;
close all;
a = input ('Enter the range of a: ')
x=(-a:a);

y=input ('Enter the values of y: ');


subplot (3,3,1)
stem(x,y)
title ('Plot')
grid on

for i=1:length(y)
y2(i)=y(((length(y)+1)-i))
end
subplot (3,3,2)
stem (x,y2)
title ('Invert Plot')
grid on

for i=1:length(y)
y3(i)=((y(i)+y2(i))/2)
end
subplot (3,3,3)
stem (x,y3)
title ('Even Plot')
grid on

for i=1:length(y)
y4(i)=((y(i)-y2(i))/2)
end
subplot (3,3,4)
Monday, January 23, 2017 Page |
Experiment 2: Generating Even, Odd, Shifting and Scaling Plots BT15ECE022
stem (x,y4)
title ('Odd Plot')
grid on

shift=input ('Value by which the plot is to be shifted: ')


x1= (-a+shift):(a+shift)
for i=1:length(y)
y5(i)=y(i)
end
subplot (3,3,5)
stem(x1,y5)
title ('Plot Shift')
grid on

scale=input('Value by which the plot is to be scaled: ')


x2= (-a/scale):(1/scale):(a/scale)
for i=1:length(y)
y6(i) = y(i)
end
subplot (3,3,6)
stem (x2,y6)
title ('Plot Scaling')
grid on

2. To generate Even and Odd Plots for a Continuous Plot.


Also Shift and Scale the Plot.
clear all;
close all;
clc
x=-2:0.01:2

for i=1:length(x)
if x(i)>=-2 && x(i)<=-1
y(i)=x(i)+1
else if x(i)>-1 && x(i)<=0
y(i)=1
else if x(i)>0 && x(i)<=1
y(i)=2
else if x(i)>1 && x(i)<2
y(i)=1
else
y(i)=0
end
end
end
end
end
subplot(3,3,1)
plot(x,y)
title('Original Plot')
grid on

for i=1:length(y)
y2(i)=y(((length(y)+1)-i))
end
Monday, January 23, 2017 Page |
Experiment 2: Generating Even, Odd, Shifting and Scaling Plots BT15ECE022
subplot(3,3,2)
plot(x,y2)
title('Invert Plot')
grid on

for i=1:length(y)
y3(i)=((y(i)+y2(i))/2)
end
subplot(3,3,3)
plot(x,y3)
title('Even Plot')
grid on

for i=1:length(y)
y4(i)=((y(i)-y2(i))/2)
end
subplot(3,3,4)
plot(x,y4)
title('Odd Plot')
grid on

shift=input ('Value by which the plot is to be shifted: ')


x1= (-2+shift):.01:(2+shift)
for i=1:length(y)
ynew(i)=y(i)
end
subplot(3,3,5)
plot(x1,y)
title('Plot Shift')
grid on

scale=input('Value by which the plot is to be scaled: ')


x2=(-2/scale):(.01/scale):(2/scale)
for i=1:length(y)
ynnew(i)=y(i)
end
subplot(3,3,6)
plot(x2,ynnew)
title('Plot Scaling')
grid on

Input

1. To generate Even and Odd Plots for a User Defined Discrete Plot.
Also Shift and Scale the Plot.
Enter the value of a as 2.
Enter the values of y as [-1,1,2,1,0].
Enter the value by which the plot is to be shifted as 5.
Enter the value by which the plot is to be scaled as 5.

2. To generate Even and Odd Plots for a Continuous Plot.


Monday, January 23, 2017 Page |
Experiment 2: Generating Even, Odd, Shifting and Scaling Plots BT15ECE022
Also Shift and Scale the Plot.
Enter the value by which the plot is to be shifted as 5.
Enter the value by which the plot is to be scaled as 5.

Output

1. To generate Even and Odd Plots for a User Defined Discrete Plot.
Also Shift and Scale the Plot.

2. To generate Even and Odd Plots for a Continuous Plot.


Also Shift and Scale the Plot.

Result
Monday, January 23, 2017 Page |
Experiment 2: Generating Even, Odd, Shifting and Scaling Plots BT15ECE022
MATLAB programs have been generated for creating a user defined discrete plot and continuous
plot. The even and odd plots have been generated and also the plots have been shifted and scaled.

Vous aimerez peut-être aussi