Report For Exp - 1 and Exp - 2
Report For Exp - 1 and Exp - 2
-01 Date:17-08-2022
AIM: MATLAB (codes) Program for computation and plotting of different expression.
1. Time scales
MATLAB Command Codes 2. Plot
Codes window/Editor in Logics 3. Axis
New Script in 4. Title
order to edit if 5. Legend
require
6. Grid on/off
PROCEDURE:-
OBJECTIVE:
>>X=[1 2 3 4 5];
>>Y=10+X;
Y=
11 12 13 14 15
Note the following functions and special constants from help abs, sin, atan, conj
,cosh, exp, log, log10, real, imag, pi, sum, diag. Calculate:. a) ln(e3)
b) log(e)
c) e π√163
Question 6: Note the functions of the linear 2D plot function “plot" and auxiliary functions
“subplot", “axis",“grid", “xlabel",”ylabel", “title".
x= -pi : pi/300 : pi; y=tan(sin(x))-sin(tan(x)); Plot
(x,y);
CODES:
x=[-pi:pi/300:pi];
y=tan(sin(x))-sin(tan(x));
plot(x,y,'r') xlabel('x')
ylabel('tan(sin(x))-sin(tan(x))')
title('2-D Curve Plot') grid on
RESULT:
Question 7: Write a program to display “too hot" if temperature>100 deg, else if temperature>90
deg display“normal temp." else display “too cool" by entering the temperature.
CODES:
RESULT:
AIM: MATLAB (codes) Program for generation and display of different functions.
PROCEDURE:-
OBJECTIVE:
ASSOCIATED PROGRAM:
t=1:0.01:20;
y=sin(2*pi*t/10);
plot(t,y,'r')
RESULTS:
Question 2: Write a program to plot a function y1(t) and y2(t) on the same figure with same scale.
Find out and plot their resultant waveforms after addition and substraction also. Where y1(t) is
same as (1) and y2(t)=cos(2π t/10), t=1:0.01:20. Insert title, axes labels and legends in the plot. Find
the use of “grid” command.
PROGRAM:
t=1:0.01:20;
y1=sin(2*pi*t/10);
y2=cos(2*pi*t/10);
f=y1+y2;
k=y1-y2;
plot(t,y1,'r',t,y2,'b',t,f,'g',t,k,'y');
xlabel('time t=1 to 20');
ylabel('functions y1, y2, f, g');
title('2-D Curve Plots between respective functions and time axes');
legend('Sinewave','Cosinewave','Addition','Substration', 'Location', 'bestoutside'); grid
on
RESULTS:
Question 3: Plot y1(t) and y2(t) separately in the same figureusing ‘subplot’ command. Plot them
in different figures with title and labels of different axes.
PROGRAM:
3(a) 3(b)
t=1:0.01:20; t=1:0.01:20;
y1=sin(2*pi*t/10); y1=sin(2*pi*t/10);
y2=cos(2*pi*t/10); y2=cos(2*pi*t/10);
subplot(2,2,1) figure
plot(t,y1,'r'); plot(t,y1,'r');
title('sine wave plot'); xlabel('Time');
subplot(2,2,2); ylabel('sine wave amplitude');
plot(t,y2,'b'); title('sine wave plot');
title('cosine wave plot') figure
plot(t,y2,'b');
xlabel('Time');
ylabel('cosine wave
amplitude');
title('cosine wave plot');
RESULTS:
Question 4: Plot y1(t) and y2(t) in 3-D boxes considering y1(t) in x-axis and y2(t) in z-axis with
t=10:0.1:10.
PROGRAM:
t=-10:0.1:10;
y1=sin(2*pi*t/10);
y2=cos(2*pi*t/10); x=y1;
y=t; z=y2; figure
plot3(x,y,z); grid on
title('3-D Curve Plot')
xlabel('sine function y1');
ylabel('time axis');
zlabel('cosine function y2')
axis tight
RESULT:
Question 5: Generate a unit step function using “stepfun”. Generate a unit gate function between
t = 4 and t = 8.
PROGRAM:
5(a) 5(b)
t=-5:0.00001:10; t1=0:0.01:4;
y1=stepfun(t,0); t2=4:0.01:8;
plot(t,y1); axis([-5 t3=8:0.01:12;
10 -1 3]); t=[t1 t2 t3];
title('A unit step function using x1=zeros(size(t1))
"stepfun"'); xlabel('Time'); ;
ylabel('Magnitude'); grid on; x2=ones(size(t2));
x3=zeros(size(t3))
; x=[x1 x2 x3];
plot(t,x,'r','LineWidth',2.5);
axis([0 12 0 1])
RESULTS:
Question 6: Write a program to generate a ramp function with a slope of tan(θ) = tan(300).
PROGRAM:
t=-10:1:10;
ramp_t=(t>=0).*t/3^0.5;
plot(t,ramp_t); axis([-20
20 -10 20]);
xlabel('Time instant');
ylabel('Amplitude');
title('ramp function with slope tan30') grid
on
legend('ramp function amplitude vs time', 'Location', 'north')
RESULTS:
PROGRAMS:
Figures (a) (L) (Top), (b) (R) (Top), (c) (L) (Bottom), (d) (R) (Bottom)
PROGRAMS:
(a) (b) (c) (d)
t=0:0.01:5; t=0:0.5:5; t=0:0.001:5; t=0:2:20;
unitstep=stepfun(t,0); figure y1=stepfun(t- y=0.6*t+2;
ramp=t.*stepfun(t,0); y1=2*t; y2=- 2,0); plot(t,y,'b');
x1=2.*t.*stepfun(t,0); 2*t+8; y2=stepfun(t- axis([0 20, 0 20]);
x2=-2.*(t- y=y1+y2; 4,0); yi=y1+y2;
1).*stepfun((t-1),0); plot(t,y1,t,y2,'r'); figure
figure axis([0 5 0 4]); plot(t,yi,'m','linewidth',.05);
plot(t/0.5,x1+x2,'b') axis([0 5 0 2]);
axis([0 5 0 5]);
RESULTS: