Soft Computing Lab Manual
Soft Computing Lab Manual
Coding:
A) AREA = Πr 2 (USING ARITHMETIC OPERATOR).
r=input(‘enter the value of radius’)
Ans: area =pi * (r)^2
Out put/Result:
exp = 1.8895e+234
PROGRAM NO 2
Coding:
x = [ 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 ]; y = 0.5 * x
–2
Out put/Result:
y = [-2 -1.75 -1.5 -1.25 -1 -0.75 -0.5 -0.25 0 0.25 .5 .75 1 1.25 1.5 1.75 2]
PROGRAM NO 3
Coding:
t=1:10
a) X = t. * sin (t)
b) Y = ( t – 1 ) ./ ( t – 2 )
Glossary:
Vector- A Vector is a special case of matrix, with just one row or one column. It is entered the same
way as a matrix.
PROGRAM NO 4
Coding:
Out put/Result:
Glossary:
linespace (a,b,n)- Generates a linearly spaced vector of length n from a to b.
plot (x,y)- Plot x vs y.
Coding:
X= linspace(0,4*pi);
Y = exp(-.4*x).*sin(x);
plot (x,y)
Out put/Result:
0.6
0.5
0.4
0.3
0.2
0.1
-0.1
-0.2
0 2 4 6 8 10 12 14
PROGRAM NO 6
Coding:
% circle – A script file to draw a unit circle. %--
----------------------------------------------------
theta = linspace(0, 2*pi,100); x =
cos (theta);
y = sin (theta); plot (x,y);
axis(‘equal’); title(‘circle of
unit radias’)
Out put/Result:
Glossary:
linespace (a,b,n)- Generates a linearly spaced vector of length n from a to b.
plot (x,y)- Plot x vs y.
title – puts a title on the plot.
PROGRAM NO 7
Aim: Write a function factorial to compute the factorial n! for any integer n.
Coding:
Aim: Write a function factorial to compute the factorial n! for any integer n.
Coding:
PROGRAM NO 9
Aim: Write a function file crossprod to compute the cross product of two vectors u and v.
Coding:
function w = crossprod(u,v);
% CROSSPROD: function to compute w =u × v for vector u & v.
% call syntax :
% w= crossprod(u,v);
% ---------------------------------------------------
If length(u)>3 / length(v)>3
error(‘ask eular.this cross prodct is beyond me.’)
end
w = [u(2)*v(3) – u(3)*v(2);
a = [1 2 3];
b = [4 5 6];
c = cross(a,b)
c=
-3 6 -3
d = dot(a,b)
d=
32
Out put/Result:
Hardware used: Pentium-4 Processor, 40GB hard disk, 256MB RAM, Keyboard, Monitor.
PROGRAM NO 10
Coding:
function s= gseriessum(r,n);
% GSERIESSUM: function to calculate the sum of a geometric series
% the series is 1+r+r^2+r^3+………+r^n.
% call syntax :
% s = gseriessum(r,n);
%-------------------------------------------------------------------------
nvector =0:n;
series = r.^n vector;
s =sum(series);
Out put/Result:
Hardware used: Pentium-4 Processor, 40GB hard disk, 256MB RAM, Keyboard, Monitor.
PROGRAM NO 11
Aim: Write a function that outputs a conversion table for Celsius and Fahrenheit.
Coding:
%--------------------------------------------------------------------------------------- C
= [ tinitial; tfinal ]’; % Create a column vector C F = (9/5)*C + 32; %
Compute corresponding F temptable = [ C F ] % make a two column matrix
of C & F
PROGRAM NO 12
Aim: Write a function to computes the interest on your account for a given principle amount, period and
rate of interest.
Competency:
Coding:
Out put/Result:
Hardware used: Pentium-4 Processor, 40GB hard disk, 256MB RAM, Keyboard, Monitor.
PROGRAM NO 13
Aim: Check following linear algebra rule for three MATRIX A,B AND C of any ranks.
a) ADDITION COMMUTATIVE.
b) ADDITION ASSOCIATIVE.
c) MULTIPLICATION WITH A SCALAR DSTRIBUTIVE.
d) MULTIPLICATION WITH A MATRIX DSTRIBUTIVE
Competency:
Coding:
% ADDITION COMMUTATIVE
y=[A+B];z=[B+A];
Out put/Result:
y= [3 8;6 13] ,z= [3 8;6 13]
% ADDITION ASSOCIATIVE
L=[(A+B)+C];M=[A+(B+C)];
Out put/Result:
L =[-2 13; 11 16] , M=[-2 13,11 16]
Out put/Result:
R=[15 40;30 65] , T=[15 40;30 65]
Hardware used: Pentium-4 Processor, 40GB hard disk, 256MB RAM, Keyboard, Monitor.
PROGRAM NO 14
Competency:
Coding:
X=A/B;
C=A*X
Out put/Result:
C=
1.0000
1.0000
2.0000
Hardware used: Pentium-4 Processor, 40GB hard disk, 256MB RAM, Keyboard, Monitor.
PROGRAM NO 15
Competency:
Coding:
a= [1 2 3;4 5 6;7 8 9]
E=eig (a)
[eigvec, eigval]=eig (a)
Out put/Result:
E=
16.1168
-1.1168
-0.0000
eigvec =
eigval =
16.1168 0 0
0 -1.1168 0
0 0 -0.0000
Hardware used: Pentium-4 Processor, 40GB hard disk, 256MB RAM, Keyboard, Monitor.