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

Report For Exp - 1 and Exp - 2

This document describes experiments conducted using MATLAB to compute and plot various mathematical functions. The first experiment involves basic computations of arithmetic, logarithmic, trigonometric and exponential functions. Various codes are provided to calculate expressions and plot the results. The second experiment focuses on simulating different functions using MATLAB toolboxes. Codes are provided to plot signals like step, ramp, sine wave, exponential and cosine wave. Additional codes demonstrate plotting multiple functions on the same graph, using subplots, and 3D plotting. The objective is to familiarize the user with MATLAB capabilities for numerical computation and visualization of mathematical expressions and signals. A variety of examples are presented to illustrate how to generate and display different functions using MATLAB.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Report For Exp - 1 and Exp - 2

This document describes experiments conducted using MATLAB to compute and plot various mathematical functions. The first experiment involves basic computations of arithmetic, logarithmic, trigonometric and exponential functions. Various codes are provided to calculate expressions and plot the results. The second experiment focuses on simulating different functions using MATLAB toolboxes. Codes are provided to plot signals like step, ramp, sine wave, exponential and cosine wave. Additional codes demonstrate plotting multiple functions on the same graph, using subplots, and 3D plotting. The objective is to familiarize the user with MATLAB capabilities for numerical computation and visualization of mathematical expressions and signals. A variety of examples are presented to illustrate how to generate and display different functions using MATLAB.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Experiment No.

-01 Date:17-08-2022

TITLE: Basic computation of arithmetic, logarithm, trigonometric and exponential


function using MATLAB.

AIM: MATLAB (codes) Program for computation and plotting of different expression.

SOFTWARE REQUIRED: MATLAB/SIMULINK

Simulink Tool box/ Library Editor Parameters


Components Browser

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:-

1. Click on File New Script


2. On resulting window, click on script or new script in order to enter into editor or simply use
command window for writing codes according to problem statements.
3. To write the codes first focus on the mathematical expression if possible to develop of asked
problem and use addition, subtractions, multiplication, and division of two or more variables
generally involved in that expression.
4. For generations of step, ramp, sine, cosine and other signals, first define the range of
independent variable and write appropriate codes for example, ‘stepfun’, or use logic of ones
and zeros, and some time heaviside command for unit step function.
5. To observe the output and waveform plot in figure window, and some time in command
window, use appropriate codes associate with Questions along with parameters highlighted
above and observe your results including waveform plot.

OBJECTIVE:

Question1: Entering and displaying constants and expressions. a);


Y =?
b) X=5; ; Y=?
c) Calculate

DISPLAYED EXPRESSION AND GOT THEIR OUTPUT:

Y=2^5/(2^5-1); X=5; a=5;


Y=4*X+12/3-100^0.5 a*[5^(3/28^(1/8)]/[2^0.5+1]^(5/6)
OUTPUT/RESULTS:

Y=1.0323 Y=14 ans=23.7083


Question 2: Entering a vector and displaying it. X
= [1 2 3 4 5]; Y = 10 + X; Y =?

CODES AND OUTPUT:

>>X=[1 2 3 4 5];
>>Y=10+X;

Y=
11 12 13 14 15

Entering and displaying matrices


a) A = [1 2; 3 4; 5 6]; A =?
b) XX = [1; 2; 3; 4]; XX =?
c) Z = [ ]; Z =?
d) I = eye(4); I =?
Question 3:

CODES AND OUTPUT:


Question 4:
Creating arrays
a) D = 1 : 4; D =?
b) D = 1 : 0.5 : 4; D =? ,length(D) =?
c) X = -1 : 0.5 : 1; Y = X. X; X =? Y =?
d) Create a vector M with 5 divisions linearly spaced between 0 and 10. Use linspace.

CODES AND OUTPUT:


Question 5:

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

CODES AND OUTPUT:

x=log(exp(3)) log10(exp(1)) exp(pi*sqrt(163))


x= ans = ans =
3 0.4343 2.6254e+17

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:

t=input('Enter temperature: ');


if t>100 disp('too hot')
elseif t>90 && t<=100
disp('normal temp')
else disp('too cool')
end

RESULT:

Enter temperature: 25 too


cool
Experiment No.-02 Date:17-08-2022

TITLE: Simulation of different functions using MATLAB Tool Box Software.

AIM: MATLAB (codes) Program for generation and display of different functions.

SOFTWARE REQUIRED: MATLAB/SIMULINK

Simulink Tool box/ Library Editor Parameters


Components Browser

Codes for 1. Time scales


1. Step signal Command 2. Plot
2. Ramp Signal window/Editor in New Codes 3. Axis
3. Sine Wave Script in order to edit if Logics 4. Title
4. Exponential require 5. Legend
5. Cosine Wave 6. Grid on/off
6. Algebraic 7. E.T.C.

PROCEDURE:-

1. Click on File New Script


2. On resulting window, click on script or new script in order to enter into editor or simply use
command window for writing codes according to problem statements.
3. To write the codes first focus on the mathematical expression if possible to develop of asked
problem and use addition, subtractions, multiplication, and division of two or more variables
generally involved in that expression.
4. For generations of step, ramp, sine, cosine and other signals, first define the range of
independent variable and write appropriate codes for example, ‘stepfun’, or use logic of ones
and zeros, and some time heaviside command for unit step function.
5. To observe the output and waveform plot in figure window, and some time in command
window, use appropriate codes associate with Questions along with parameters highlighted
above and observe your results including waveform plot.

OBJECTIVE:

Question1: Write a program to plot y(t)=sin(2πt/10), t=1:0.01:20.

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:

Question 7: Generate the curves of the following equations:


a) x.sin(x)
b) x2.sin(x2)
c) ex.sin(x)
d) e−x.sin(x)

PROGRAMS:

x.sin(x) x2.sin(x2) ex.sin(x) e−x.sin(x)


x=0:pi/100:2*pi; x=0:pi/100:2*pi; x=0:pi/100:2*pi; x=0:pi/100:2*pi;
figure x=x; figure x=x; figure x=x; figure x=x; y=exp(-
y=x.*sin(x); y=x.^2.*sin(x.^2); y=exp(x).*sin(x); x).*sin(x); plot(exp(-
plot(x.*sin(x),'r'); plot(x.^2.*sin(x.^2),'r') plot(exp(x).*sin(x),'r') x).*sin(x),'r'); xlabel('x
xlabel('x axis'); ; xlabel('x axis'); ; xlabel('x axis'); axis'); ylabel('y axis');
ylabel('y axis'); ylabel('y axis'); ylabel('y axis'); title('exp(-x).*sin(x)
title('x.*sin(x) title('x.^2.*sin(x.^2) title('exp(x).*sin(x) curve plot'); grid on axis
curve curve plot'); grid on axis curve plot'); grid on tight
plot'); tight axis tight
grid on
axis
tight
RESULTS:
Question 8: Generate the following functions and display:

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:

You might also like