0% found this document useful (0 votes)
51 views6 pages

DSP Lab 1

This lab report contains 4 MATLAB questions and their solutions: 1) A script to calculate the factorial of a user-input number N. 2) A function to calculate the volume and surface area of a cube from its edge length. 3) A script to plot 3 sine functions on the same plot in different colors. 4) A script using subplot to plot the same 3 sine functions separately in 3 subplots.

Uploaded by

FarukIslam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views6 pages

DSP Lab 1

This lab report contains 4 MATLAB questions and their solutions: 1) A script to calculate the factorial of a user-input number N. 2) A function to calculate the volume and surface area of a cube from its edge length. 3) A script to plot 3 sine functions on the same plot in different colors. 4) A script using subplot to plot the same 3 sine functions separately in 3 subplots.

Uploaded by

FarukIslam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Department of EEE

Course: DSP lab (EEE 312)


Lab Report 1
Submitted to: Haider
Adnan Khan
Group members:
Fateh Mohammed
021123033
Awmi Kaisar
021122130

id:
id:

Ques.1: Write a MATLAB script


to calculate N! = 1.2.3.4. N
where N is a user input.
clc
clear all
close all
n=input('enter value of n:');
s=1;
for(i=1:n)
s=s*i;
end
s

Result:
enter value of n:4
s=
24

>>

Ques.2: Write MATLAB


function that will calculate the
volume and surface area of
a cube from its edge length.
[Hint: Edge Length = x;
Volume = x3 surface area =
6x2]
function [ v,a ] = volume_and_area( x )
v=x^3;
a=6*x^2;
end
Result:
>> [ v,a ] = volume_and_area( 3 )
v=

27
a=
54
>>

Ques.3:

Write MATLAB script to plot


10sin(x), 5sin(2x) and 2sin2(x) for 0<x< on
the same plot in three different colors.
.

clc
clear all
close all
x=0:0.01:pi;
plot(x,10*sin(x),'g')
hold on
plot(x,5*sin(2*x),'r')
plot(x,2*(sin(x)).^2,'k')
Result:

Ques.4: Use the subplot command to


divide the plot into 3 rows and 1 column and
plot 10sin(x), 5sin(2x) and 2sin2(x) [for
0<x<] separately on each plot.

clc
clear all
close all
x=0:0.01:pi;
subplot(3,1,1)
plot(x,10*sin(x),'g')
subplot(3,1,2)
plot(x,5*sin(2*x),'r')

subplot(3,1,3)
plot(x,2*(sin(x)).^2,'k')
Result:

You might also like