100% found this document useful (1 vote)
213 views29 pages

Pragya Scilab

The document contains the source code and output for computing Fourier series approximations of various functions over different intervals. It evaluates the Fourier coefficients and plots the original functions against the approximations for half range cosine and sine series of x^2 from 0 to 2, x from 0 to pi, and compares the graphs.

Uploaded by

tkartikeya44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
213 views29 pages

Pragya Scilab

The document contains the source code and output for computing Fourier series approximations of various functions over different intervals. It evaluates the Fourier coefficients and plots the original functions against the approximations for half range cosine and sine series of x^2 from 0 to 2, x from 0 to pi, and compares the graphs.

Uploaded by

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

LAB REPORT

EXPLORATION WITH CAS –I


BBS01T1001
B.TECH-COMPUTER SCIENCE AND ENGINEERING
(2021-2022)
( 2022- 2023)
SUBMITTED BY: SUBMITTED TO:
Name: Rahul
PragyaKesarwani
Maheshwari
Dr. Aradhana Dutt
Section: 16
20(P2) Jauhari
Admission No: 22SCSE1011304
21SCSE1011187
Experiment-1

1. Evaluate:
(i) 271/3+ 320.2
(ii) 64^ (1/2) +e^4
(iii) sin (π/6)+cos60°
(iv) 4! +ln2+log100
(v) (2+3i)(4+5i)

2. By assigning values 2 and 5 to variables a and b


respectively, compute
(i) c=(a+b)2
(ii) d=4a-3b+lna+ c2

3. Write the script file for the problem:


The radius of a circle is 2cm. Find its area.
SOURCE CODE: - OUTPUT:-

1)
I. 27^(1/3)+32^.2 5

II. (2) sqrt(64)+exp(4) 62.598150

III. (3) sin(%pi/6)+cosd(60) 1

IV. (4) factorial(4)+log(2)+log10(100) 26.693147

V. (5) (2+3*%i)*(4+5*%i) -7. + 22.i

2)

I. a=2
b=5 49
c=(a+b)^2
disp(c)

II. d=4*a-3*b+log(a)+c^2 2394.6931


disp(d)

3)
r=2
area=(%pi*r^2) 12.566371
disp(area)
EXPERIMENT-3

To write a Scilab code to find the solution of following problems:

1. To find volume and total surface area of a cylinder


using input function.
2. To find whether an integer entered by user is odd or even, using if- else-
end command.
3. To find whether a real number entered by user is negative, zero or a
positive using if- elseif-else-end command.
4. To find the sum of first n natural numbers, using for loop.
5. To find the sum of first n natural numbers, using while loop.
6. To find factorial of a number using for loop.
7. To find factorial of a number using while loop.
8. To find first 20 terms of Fibonacci sequence using for loop
9. To find volume and total surface area of a cylinder using user defined
function
SOURCE CODE: - OUTPUT:-

1. clc
clear
r=input ("ENTER THE VALUE OF RADIUS:")
h=input ("ENTER THE VALUE OF HEIGHT:")
V=%pi*r^2*h;
TSA=2*%pi*r*(h+r);
disp ("Volumeis:",V)
disp ("Total Surface Area is:",TSA)

2. clc
clear
a=input("ENTER THE NUMBER: ")
if(modulo(a,2)==0)then
disp("THIS IS AN EVEN NUMBER")
else
disp("THIS IS AN ODD NUMBER")
end

3. clc
clear
a=input("ENTER THE NUMBER:")
if (a>0)then
disp("IT IS A POSITIVE NUMBER")
elseif(a<0)then
disp("IT IS A NEGATIVE NUMBER")
elseif(a==0)
disp("THIS NUMBER IS ZERO")
end
SOURCE CODE: - OUTPUT:-

4. clc
clear
n=input("ENTER NO OF TERMS: ")
sum=0;
for i=1:n
sum=sum+i
end
disp(sum)

5. clc
clear
n=input("ENTER NO OF TERMS: ")
sum=0;
i=1
while(i<=n)
sum=sum+1;
i=i+1;
end
disp(sum)

6. clc
clear
n=input("ENTER THE NO. OF TERMS: ")
A=factorial(n)
if(n<=0)then n=1
else
n=n*factorial(n-1)
end
disp(A)
SOURCE CODE: - OUTPUT:-

7. clc
clear
n=input("ENTER THE NO. OF TERMS: ")
factorial=1;
while(n>0)
factorial=n*factorial;
n=n-1;
end
disp(factorial)

8. clc
clear
n=input("ENTER NO.OF TERMS: ")
s=zeros(1,20); s(1)=1; s(2)=1;
for i=3:20
s(i)=s(i-2)+s(i-1);
end
disp("FIBONACCI
SERIES",s)
Experiment-4
1) To plot Parabola x2=4ay. Take focal length a=1
2) To plot Circle. x2+y2=a2 . Take a=1
3) To plot Ellipse. x2/ a2 + y2/ b2 =1. Take a=4, b=3
4) To plot Hyperbola. x2/ a2 - y2/ b2 =1 , Take a=3, b=4
5) To plot a Plane ax+ by +cz=d. Take a=b=-1, c=1, d=4. z=4+x+y
6) To plot (elliptical )paraboloid z/c= x2/a2 +y2/b2 . Take a=b=c=1
7) To plot (elliptical ) Cone. (z/c)^2=(x^2/4+y^2/9 )Take a=b=c=1
8) To plot right circular Cylinder. x2+y2=a2
9) To plot Sphere x2+y2 +z2 =a2 , Take a=1
10) To plot Ellipsoid. x2/a2 +y2/b2 + z2/c2 =1 . Take a=4,b=3,c=2
11) To plot Hyperboloid x2/a2 +y2/b2 - z2/c2 =1 . Take a=4,b=3,c=2
SOURCE CODE: - OUTPUT:-

1)
clc
clear
clf
x=linspace(-1,1,100);
y=x^2;
plot(x,y)

2)
clc
clear
clf
a=0;
b=0;
r=1;
theta=linspace(0,2*%pi,100);
x=a+r*cos(theta);
y=b+r*sin(theta)
plot(x,y)

3)
clc
clear
clf
a=4;
b=3;
x0=0;
y0=0;
t=-%pi:0.01:%pi;
x=x0+a*cos(t);
y=y0+b*sin(t);
plot(x,y)
SOURCE CODE: - OUTPUT:-

4)
clc
clear
clf
a=3,b=4;
functionf=hyperbola(x,y);
f=(x^2/9)-(y^2/16);
endfunction
xdata=linspace(-10,10,1000);
ydata=linspace(-10,10,1000);
contour(xdata,ydata,hyperbola,1)

5)
clc
clear
clf
function z=f(x, y)
z=4+x+y;
endfunction
x=linspace(-2,2,100);
y=linspace(-2,2,200);
z=feval(x,y,f)';
clf
surf(x,y,z)
SOURCE CODE: - OUTPUT:-

6)
clc
clear
clf
function z=f(x, y)
z=x^2+y^2;
endfunction
x=linspace(-1,1,100);
y=linspace(-1,1,200);
z=feval(x,y,f)';
clf
surf(x,y,z)

7)
clc
clear
function z=f(x, y)
z=sqrt(x^2/1+y^2/1);
endfunction
x=linspace(-300,300,50);
y=linspace(-300,300,50);
z=feval(x,y,f)';
clf
surf(x,y,z)

8)
clc
clear
t=linspace(0,2*%pi,100);
x1=linspace(0,3,100);
[T,X1]=meshgrid(t,x1);
x=2*cos(T);y=2*sin(T);z=(X1);
surf(x,y,z)
SOURCE CODE: - OUTPUT:-

9)
clc
clear
a =linspace(0,360,100);
th=linspace(-90,90,50);
R =1;
[A,Th]=meshgrid(a,th);
Z = R*sind(Th);
X = R*cosd(Th).*cosd(A);
Y = R*cosd(Th).*sind(A);
Ncolors=400;
clf
surf(X,Y,Z)

10)
clc
clear
a =linspace(0,360,100);
th=linspace(-90,90,50);
R =1;
[A,Th]=meshgrid(a,th);
Z =2*R*sind(Th);
X =4*R*cosd(Th).*cosd(A);
Y =3*R*cosd(Th).*sind(A);
Ncolors=200;
clf
surf(X,Y,Z)
SOURCE CODE: - OUTPUT:-
11)
clc
clear
a =linspace(0,360,100);
th=linspace(-90,90,50);
R =1;
[A,Th]=meshgrid(a,th);
Z =2*R*sinh(Th);
X =4*R*cosh(Th).*cosd(A);
Y =3*R*cosh(Th).*sind(A);
Ncolors=300;
clf
surf(X,Y,Z)
Experiment-5

1. To find the error in estimating the value of function f(x)=ex at


x=1 using its Taylor series expansion about origin.

2. To find the error in estimating the value of function


f(x)=sinx at x=pi/2 using its Taylor series expansion about
origin.

3. To compare the function f(x)=ex and its Taylor series


expansion about origin by using 2d plots.

4. To compare the function f(x)=sinx and its Taylor


series expansion about origin by using 2d plots.
SOURCE CODE: - OUTPUT:-

1)
Clc
clear
a=0
x=1
n=20 "error"
y=exp(x)
yest=0 2.7182818
for i=0:n
yest=yest+((x^n)/factorial(n))
end
error=abs(y-yest)
disp("error",error)

2)
Clc
Clear
a=0
x=%pi/2
n=2 "error"
y=sin(x)
yest=0 0.0796926
for i=0:n
y=yest+((-1)^n*(x^(2*n+1))/factorial(2^n+1))
end
error=abs(y-yest)
disp("error",error)
SOURCE CODE: - OUTPUT:-
3)
clc
clear
clf
x=linspace(-2,2,100)
a=0
n=10
y=exp(x)
plot(x,y)
a=0
yest=0
for i=0:n
yest=yest+(x^n)/factorial(n)
end
plot(x,yest)

4)
Clc
clear
clf
x=linspace(-%pi,%pi,100)
a=0
n=20
y=sin(x)
plot(x,y)
yest=0
for i=0:n
yest=yest+((-1)^i*(x^(2*i+1))/factorial(2^i+1))
end
plot(x,yest,"g")
EXPERIMENT-6
1. To find the Fourier coefficients of the Half range cosine
series of y=f(x)= x2 in (0,2) and compare the graph of the
function and the series.

2. To find the Fourier coefficients of the Half range sine series


of y=f(x)= x2 in (0,2) and compare the graph of the
function and the series.

3. To find the Fourier coefficients of the Half range cosine


series of y=f(x)= x in (0, pi) and compare the graph of the
function and the series.

4. To find the Fourier coefficients of the Half range sine series


of y=f(x)= x in (0, pi) and compare the graph of the
function and the series.
SOURCE CODE: - OUTPUT:-

1.
clc
clear
clf l=2
n=input("enter value of n")
x=linspace(0,2,100)
a0=(2/l)*integrate('x^2','x',0,l,1e-2)
for (i=1 : n)
a(i)=(2/l)*integrate('(x^2)*cos(i*%pi*(x/l))','x',0,l,1e-2)
end
disp("a0=",a0,"an=",a) y=x^2 s=a0/2
for (i=1 : n)
s=s+a(i)*cos(i*%pi*(x/l))
end
plot(x,y,"m",x,s,"k")
SOURCE CODE: - OUTPUT:-

2.
clc
clear
clf
l=2
n=input("enter value of n")
x=linspace(0,2,100)
for (i=1 : n)
b(i)=(2/l)*integrate(‘(x^2)*cos(i*%pi*(x/l))’,'x',0,l,1e-2)
end
disp("bn=",b)
y=x^2
s=0
for (i=1 : n)
s=s+b(i)*sin(i*%pi*(x/l))
end
plot(x,y,"m",x,s,"k")
SOURCE CODE: - OUTPUT:-

3.
clc
clear
clf
l=%pi
n=input("enter value of n")
x=linspace(0,%pi,100)
a0=(2/l)*integrate('x','x',0,l,1e-2)
for (i=1 : n)
a(i)=(2/l)*integrate('(x)*cos(i*%pi*(x/l))','x',0,l,1e-2)
end
disp("a0=",a0,"an=",a)
y=x s=a0/2
for (i=1 : n)
s=s+a(i)*cos(i*%pi*(x/l))
end
plot(x,y,"m",x,s,"k")
SOURCE CODE: - OUTPUT:-

4.
clc
clear
clf
l=%pi
n=input("enter value of n")
x=linspace(0,%pi,100)
for (i=1 : n)
b(i)=(2/l)*integrate('(x)*cos(i*%pi*(x/l))','x',0,l,1e-2)
end
disp("bn=",b)
y=x s=0
for (i=1 : n)
s=s+b(i)*sin(i*%pi*(x/l))
end
plot(x,y,"m",x,s,"k")
Experiment-7

1)

2)

3)

4)
SOURCE CODE: - OUTPUT:-

1)
clc
clear
function z=f(x, y)
z=x*y
endfunction
x=[0,0;1,0;1,1]
y=[2,2;4,4;2,4]
[I,e]=intg2d(x,y,f)
disp("value of integral= ",I);
disp("error= ",e);

2)
clc
clear
function z=f(x, y)
z=x*y
endfunction
x=[1,1;2,1;2,2]
y=[3,3;4,4;3,4]
[I,e]=intg2d(x,y,f)
disp("value of integral= ",I);
disp("error= ",e);
SOURCE CODE: - OUTPUT:-

3)
clc
clear
function z=f(x, y)
z=x^2+y^2
endfunction
x=[1,1;4,1;4,4]
y=[0,0;1,1;0,1]
[I,e]=intg2d(x,y,f)
disp("value of integral= ",I);
disp("error= ",e);

4)
clc
clear
function z=f(x, y)
z=exp(x^2+y^2)
ndfunction
x=[0,0;1,0;1,1]
y=[0,0;1,1;0,1]
[I,e]=intg2d(x,y,f)
disp("value of integral= ",I);
disp("error= ",e);

You might also like