Experiment No.-8: Aim:-Tool Used: - Program Code

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Experiment No.

-8
Aim:-To write a MATLAB program to compute factorial for n=50.
Tool Used:-MATLAB 7.0.4.
Program Code
f=1;
for i=1:1:50
f=f*i;
end
fprintf(factorial of 50 is=%d,f)

Output
factorial of 50 is=3.041409e+64

Experiment No.-9

Aim:-To write a MATLAB program to calculate sum of all powers


of 2 below fifty using while command.
Tool Used:-MATLAB 7.0.4.

Program code
s=0; k=0;
while k<=49
s=s+2k;
k=k+1;
end
fprintf(sum of powers of 2 below fifty is=%d,s)

Output

sum of powers of 2 below fifty is=1125899906842623.

Experiment No.-10
Aim:-To write a MATLAB program to

Tool Used:-MATLAB 7.0.4.


Program Code
a=1; c=0; b=0;
n=input(Enter a number\n)
fprintf(%d,b)
for k=1:1:n
c=a+b;
a=b;
b=c;
fprintf(\n%d\n,c)
end

Output
Enter a number
10
n = 10
0
1
1
2
3
5
8
13
21
34
55

Experiment No.-11
Aim:-To write a MATLAB program to plot a circle of radius 5.
Tool Used:-MATLAB 7.0.4.

Program Code
t=-5:.001:5
y=5*cos(t);
x=5*sin(t);
plot(x,y)

Output

Experiment No.-12
Aim:-To write a MATLAB program to plot the following curves
(1)sinc(x)
(2)(1/(x-1)2)+x

(3)(x2+1)/(x2-4)
(4)((10-x)2/3-2)/(4-x2)1/2
Tool Used:-MATLAB 7.0.4.

Program Code

x=-3*pi:.001:3*pi
y=sinc(x)
subplot(2,2,1)
plot(y),xlabel(x),ylabel('sinc(x)')
x=-5:.05:5
y=(1./(x-1).^2)+x
subplot(2,2,2)
plot(y),xlabel('x'),ylabel('y=(1./(x-1).^2)+x')
x=-5:.05:5
y=(x.^2+1)./(x.^2-4)
subplot(2,2,3)
plot(y),xlabel('x'),ylabel('y=(x.^2+1)./(x.^2-4)')
x=-10:.001:10
y=(((10-x).^(2/3))-2)./(4-x.^2).^(1/2)
subplot(2,2,4)
plot(y),xlabel('x'),ylabel('y=(((10-x).^(2/3))-2)./(4-x.^2).^(1/2)')

Output

You might also like