Pragya Scilab
Pragya Scilab
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)
1)
I. 27^(1/3)+32^.2 5
2)
I. a=2
b=5 49
c=(a+b)^2
disp(c)
3)
r=2
area=(%pi*r^2) 12.566371
disp(area)
EXPERIMENT-3
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)
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.
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);