Professional Documents
Culture Documents
MANUAL
I Sem EC /CS
(22MATS11)
SOURCE CODE:
2D Polar plot:
a) t=0:0.01:2*%pi;
clf();polarplot(sin(7*t),cos(8*t))
clf();polarplot([sin(7*t')sin(6*t')],[cos(8*t'),cos(8*t')],[1,2])
b) theta=0:0.01:2*%pi;
a=1
r=a*(1-cos(theta));
polarplot(theta,r)
2D cartesian plot:
x=-2:0.01:2;
y1=sqrt(1-x^2);
y2=-sqrt(1-x^2);
plot(x,y1,x,y2)
2D Polar plot:
RESULT:
Thus the partial derivatives and jacobians program was executed successfully.
function dx=f(x, y)
dx=-2*x-y;
endfunction
y0=-1;
x0=0;
t=0.4;
sol=ode(y0,x0,t,f);
disp(sol,"answer");
plot2d(x,sol,5)
xlabel('x');
ylabel('y(x)');
xtitle('y(x)vs x');
funcprot(0)
clf;
function dx=f(x, y)
dx=exp(-x);
endfunction
y0=0;
x0=0;
x=[0:0.5:10]
sol=ode(y0,x0,x,f);
plot2d(x,sol,5)
xlabel('x');
ylabel('y(x)');
xtitle('y(x)vs x');
SOURCE CODE:
clc;
clear;
function gcd(a, b)
x=a
y=b
while y~=0
r=modulo(x,y)
x=y
y=r
end
mprintf("gcd(%d,%d)=%d",a,b,x)
endfunction
n1=input("enter first no:")
n2=input("enter second number:")
gcd(n1,n2)
RESULT:
Thus the GCD of two numbers using euclids algorithm was executed
successfully.
RESULT:
Thus the linear congruences was solved and executed successfully.
enter no of iterations 3
"x1,x2,x3 after1iteration"
"x1,x2,x3 after2iteration"
"x1,x2,x3 after3iteration"
clc
n=input("enter no of variables")
disp('enter the coefficient matrix,rowwise')
for i=1:n;
for j=1:n;
A(i,j)=input("")
end
end
disp("enter the constant matrix,column")
for i=1:n;
c(i)=input("")
end
clc
N=input("enter no of variables")
disp('enter the coefficient matrix,rowwise')
for i=1:N;
for j=1:N;
A(i,j)=input("")
end
end
disp("enter the constant matrix,column")
for i=1:N;
C(i)=input("")
end
disp(A)
disp(C)
if rank(A)==rank([A c])then
if rank(A)==min(size(A))then
mprintf("\n system of equation has unique solution:\n")
else
mprintf("\n system of equation has infinitely many solution:\n")
end
if rank(A)<>rank([A C]) then
mprintf("\n system of equation has no solution:\n");
D=inv(A)*C
clear
clc
xset('window',1)
xtitle("my graph","x axis","y axis")
x=linspace(1,3,30)
y1=3-x
y2=%e^(x-1)
plot(x,y1,"o-")
plot(x,y2,"+-")
legend("3-x","%e^(x-1)")
disp("from the graph, it is clear that the point of intersection is nearly x=1.43")
Equation : 2x+y+z=5
x+y+z=1
x-y+2z=1
enter no of variables 3
"enter the coefficient matrix,rowwise"
2
1
1
1
1
1
1
-1
2
"enter the constant matrix,column"
5
4
1
2 1 1
1 1 1
1 -1 2
5
4
1
1
2.0000000
1.0000000
enter no of variables 3
enter the coefficient matrix,rowwise''
4
6
5
9
2
4
9
6
2
enter the constant matrix,column
1
7
9
4. 6. 5.
9. 2. 4.
9. 6. 2.
1
7
9
system of equation has unique solution:
1.1153846
0.0961538
-0.8076923
RESULT:
Thus the numerical solution of system of linear equations, test for consistency
and graphical representation was executed successfully.
clear;clc;close();
A=[3 0 1;2 2 2;4 2 5];
disp(A,'the given matrix is')
u0=[1 1 1]';
disp(u0,'the intial vector is')
v=A*u0;
a=max(u0);
disp(a,'first approximation to eigen value is');
while abs(max(v)-a)>0.002
disp(v,"current eigen vector is")
a=max(v);
disp(a,"current eigen value is")
u0=v/max(v);
v=A*u0;
end
format('v',4);
disp(max(v),'the largest eigen value is:')
format('v',5)
disp(u0,'the corresponding eigen vector is:')
(ii)
the given matrix is
3. 0. 1.
2. 2. 2.
4. 2. 5.
the intial vector is
1.
1.
1.
first approximation to eigen value is
1.
current eigen vector is
4.
6.
RESULT:
Thus the eigen value and eigen vectors can be computed by Rayleigh power
method. Also the largest and smallest eigen values also computed and executed
successfully.
OUTPUT:
maxima value of given function is infinite and minima value is 2
RESULT:
Thus the maxima and minima values are computed successfully by scilab.