Mathematics SciLab
Mathematics SciLab
Date:
clc
clear
A = [4 5 8 6]
disp(A)
B = [4;7;2;6]
disp(B)
C = [1 2 3 ; 2 4 6 ; 3 6 9 ]
disp(C)
D = [4 5 8; 2 3 6; 9 5 7]
disp(D)
disp(C(:,3))
disp(det(C))
disp(inv(C))
disp(rank(C))
disp(trace(C))
E=C+D
disp(E)
F=C*D
disp(F)
disp(6*C)
—-------------------------------------------------
clc
clear
v1 = [2 2 1]
v2 = [1 -1 1]
v3 = [1 0 1]
v = [v1; v2; v3]
disp(v)
r = rank(v)
if r == 3 then
disp "it is Linearly Inependent"
else
disp "It is Lineraly dependent"
end
—--------------------------------------------------
clc
clear
v1 = [1 2 3 1]
v2 = [2 1 -1 1]
v3 = [4 5 5 3]
v4 = [5 4 1 3]
[row c] = size(v)
r = rank(v)
if r == row then
disp "it is Linearly Inependent"
else
disp "It is Lineraly dependent"
end
—------------------------------------------------------
clc
clear
v1 = [2 -3 1]
v2 = [1 -1 2]
v3 = [2 1 -3]
if Y == zeros(Y) then
disp(X)
else
disp("System is inconsistent")
end
—---------------------------------------
Date: 05/04/2022
ra = rank(v)
[row c] = size(v)
if ra == row then
disp("Vectors are Linearly Independent")
else
disp("Vectors are Linearly Dependent")
end
clc
clear
a1 = [2 -3 1]
a2 = [1 -1 2]
a3 = [2 1 -3]
a = [a1; a2; a3]
b = [-2; 3; -2]
x = inv(a) * b
disp(x)
a1 = [2 2 -5]
a2 = [-2 4 3]
a3 = [-1 3 2]
b = [1; 6; 5]
x = inv(a) * b
disp(x)
a = [1 2 3; 4 5 6; 2 4 1]
disp("inverse of A is: " )
disp(inv(a))
disp("Determinant of A is: " )
disp(det(a))
disp("Trace of A is: " )
disp(trace(a))
disp("Rank of A is: " )
disp(rank(a))
4. Write the given system of equation in matrix form.
2x1+2x2-5x3=1, -2x1+4x2+3x3=6, -x1+3x2+2x3=5 and solve it for finding the values
ofxi’s.
clc
clear
a1 = [2 2 -5]
a2 = [-2 4 3]
a3 = [-1 3 2]
b = [1; 6; 5]
x = inv(a) * b
disp(x)
5. Given two Matrices as
A=[1 2 3; 4 5 6; 2 4 1], B=[2 3 4; 6 7 8; 9 7 4]
Write (a)inverse (b)rank (c) trace and determinant of a matrices.
clc
clear
a=[1 2 3; 4 5 6; 2 4 1]
b=[2 3 4; 6 7 8; 9 7 4]
disp("inverse of A is: " )
disp(inv(a))
disp("Determinant of A is: " )
disp(det(a))
disp("Trace of A is: " )
disp(trace(a))
disp("Rank of A is: " )
disp(rank(a))
x = inv(a) * b
disp(x)
7. Check for Linear independency/ dependency for the given set of vectors using SciLab-
[1,2,3] [3,4,4] [7,10,12]
clc
clear
a1 = [1,2,3]
a2 = [3,4,4]
a3 = [7,10,12]
ra = rank(a)
[row c] = size(a)
if ra == row then
else
End
clear
a1 = [2 -3 1]
a2 = [1 -1 2]
a3 = [2 -1 3]
b = [-2; 3; -2]
x = inv(a) * b
disp(x)
clear
a1 = [1 4 7]
a2 = [2 5 8]
a3 = [1 2 3]
b = [1; 2; 1]
x = inv(a) * b
disp(x)
clear
a1 = [1 -4 7]
a2 = [3 8 -2]
a3 = [7 -8 26]
b = [8; 6; 3]
x = inv(a) * b
disp(x)
0.
Date: 12/04/2022
clc
clf
clear
function [ydot]=myfuntion(x, y)
ydot = x+y
endfunction
x1 = 0
y1 = 1
x = linspace(0,1,100)
y = ode(y1, x1, x, myfuntion)
disp(x,y)
plot(x,y)
2. Write a scilab code to find solution of the first order initial value problem at x=0.8:
3. Solve and Plot the solution: (dx/dt)+(tant)x=cost, y(0)=0 ; in interval [0,1]
clc
clf
clear
function [tdot]=myfuntion(x, t)
tdot = cos(t) - x*tan(t)
endfunction
x1 = 0
y1 = 0
x = linspace(0,1,100)
y = ode(y1, x1, x, myfuntion)
disp(x,y)
plot(x,y)
4.
clc
clf
clear
function [ydot]=myfuntion(x, y)
ydot = -2*x - y
endfunction
x1 = 0
y1 = -1
x = linspace(0,1,100)
y = ode(y1, x1, x, myfuntion)
disp(x,y)
plot(x,y)
5.
clc
clf
clear
function [ydot]=myfuntion(x, y)
ydot = 2*x*y
endfunction
x1 = 0
y1 = 1.8
x = linspace(0,1,100)
y = ode(y1, x1, x, myfuntion)
disp(x,y)
plot(x,y)
6.
clc
clf
clear
function [ydot]=myfuntion(x, y)
ydot = 4*x
endfunction
x1 = 0
y1 = 3
x = linspace(0,1,100)
y = ode(y1, x1, x, myfuntion)
disp(x,y)
plot(x,y)
7.
clc
clf
clear
function [ydot]=myfuntion(x, y)
ydot = -4*x
endfunction
x1 = 0
y1 = 3
x = linspace(0,1,100)
y = ode(y1, x1, x, myfuntion)
disp(x,y)
plot(x,y)
Date: 26/04/2022
clear
clc
clf
//solution of y^2-5y^1+y=0
function dx=f(t, x)
dx(1)=x(2)
dx(2)=(-1/2)*x(1)+5/2*x(2)
endfunction
sol=ode([6;-1],3,4,f)
//disp(sol(1))
t=4:.5:10;
sol=ode([6;-1],3,t,f)
plot(t,sol(1,:))
To be corrected:
clc
clear
clf
function zdash=f(c, z)
zdash = c*z
endfunction
c = [0 0 1; exp(x) -6 -5]
z = [1; 0; 1]
z0 = [0 1]
x = linspace(0,1,100)
y = ode( [0;1],0, x,f)
disp(x,y)
plot(x,y)
Date: 24/05/2022
clc
clear
clf
deff('a=f(x)','a=x*x')
function bn=f2(x, f)
bn = f(x)*sin(i*%pi*x/l)
endfunction
A(i) = (1/l)*integrate('f1(x)','x',-l,l)
B(i) = (1/l)*integrate('f2(x)','x',-l,l)
end
x = -5*l:0.1:5*l
series = a0/2;
for i=1:n
series = series + A(i)*cos(i*%pi*x/l) + B(i)*sin(i*%pi*x/l)
end
plot(x,series)
endfunction
myfourier(2,6,f)
Write the SciLab code for the solution of one dimensional wave equation subjected to
u(0,t)=u(L,t)=0, with initial velocity zero, if the initial conditions for displacement is given by
f(x)= sin3x . Use the values of c=1, L=1. Also find the displacement in the string when x=0.5
and t=0.075
clc
clear
clf
function w=f(x)
w = sin(3*%pi*x)
endfunction
for i=1:n
function w1=f1(x)
w1 = f(x)*sin(i*%pi*x/l)
endfunction
b(i) = (2/l)*integrate('f1(x)','x',0,l)
end
function u=f2(x, t)
u=0
for i=1:n
u = u + b(i)*sin(i*%pi*x/l)*cos(i*%pi*k*t/l)
end
endfunction
x = 0:0.05:1
t = 0:0.025:0.25
f1 = feval(x,t,f2)
plot3d(x,t,f1,'x@t@f2(x,t)')
scf(1)
plot(x',f1(:,1),'m.*',x',f1(:,3),'g.-',x',f1(:,6),'b.+',x',f1(:,9),'r.x')
Date: 31/05/2022
Write the SciLab code for the solution of one dimensional heat equation
subjected to u(0,t)=u(L,t)=0, if the initial conditions are given by u(x,0)=f(x)=4*(x/L)*(1-
x/L). Use the values of k=1, L=1. Also find the temperature in rod at x=0.4,t=0.2
clc
clear
clf
function w=f(x)
w = 4*x/l*(1-x/l)
endfunction
for i=1:n
function w1=f1(x)
w1 = f(x)*sin(i*%pi*x/l)
endfunction
b(i) = (2/l)*integrate('f1(x)','x',0,l)
end
function u=f2(x, t)
u=0
for i=1:n
u = u + b(i)*sin(i*%pi*x/l)*exp(-i^2*%pi^2*k*t/l^2)
end
endfunction
x = 0:0.05:1
t = 0:0.025:0.25
f1 = feval(x,t,f2)
plot3d(x,t,f1,'x@t@f2(x,t)')
scf(1)
plot(x',f1(:,1),'m.*',x',f1(:,3),'g.-',x',f1(:,6),'b.+',x',f1(:,9),'r.x')
Write the SciLab code for the solution of Two dimensional Laplace equation subjected to
u(x,0)=0, u(x,H)= 100*x*(L-x)^3, u(0,y)=u(L,y)=0. Use the values of H=1, L=2.
clc
clear
clf
function w=f(x)
w = 100*x*(l-x)^3
endfunction
function w1=f1(x)
w1 = f(x)*sin(n*%pi*x/l)
endfunction
function a=a1(n)
a = 2*intg(0,l,f1,0.0001)/(l*sinh(n*%pi*h/l))
endfunction
l=2
h=1
a = []
for n=1:20
a = [a a1(n)]
end
function u=u1(x, y)
u=0
for j=1:20
u = u + a(j)*sin(j*%pi*x/l)*sinh(j*%pi*y/l)
end
endfunction
x = 0:l/40:l;
y = 0:h/20:h;
u2 = feval(x,y,u1)
plot3d(x,y,u2,25,5,'x@t@u(x,t)')
scf(1)
contour(x,y,u2,15)
xtitle('Contour plots for Laplace equation','x','y')
To verify Rank theorem, rank+ nullity=No. of columns in the matrix, for an m X n matrix A.
clc
clear
r = rank(A)
disp(r)
k = kernel(A)
nullity = size(k,2)
disp(nullity)
n = size(A,2)
disp(n)
if (r + nullity) == n then
disp("Rank Nullity Theorem Verified")
end
B = [2 5 -3 -4 8; 4 7 -4 -3 9; 6 9 -5 2 4; 0 -9 6 5 -6]
r = rank(B)
disp(r)
k = kernel(B)
nullity = size(k,2)
disp(nullity)
n = size(B,2)
disp(n)
if (r + nullity) == n then
disp("Rank Nullity Theorem Verified")
end
For the system of linear equations: X+4y+7z=1, 2x+5y+8z=2, x+2y+3z=1
Does the solution exist?
How many free variables are there in solution?
Find the solution.
clc
clear
A = [1 4 7; 2 5 8; 1 2 3]
//X = [x1; x2; x3]
B = [1; 2; 1]
X = inv(A)*B
disp(X)
k = kernel(A)
nullity = size(k,2)
disp(nullity)
Show that the set of vectors (2,2,1), (1,-1,1), (1,0,1) forms a basis for space R3 ?
(ii)Find the coordinates of the vector (4,2,1) w.r.t. the basis set given in (i)
clc
clear
A = [2 1 1; 2 -1 0; 1 1 1]
//X = [x1; x2; x3]
B = [4; 3; 1]
X = inv(A)*B
disp(X)
X = inv(A')*B
disp(X)
Date: 07/06/2022
u1 = [3 0 4]
u2 = [-1 0 7]
u3 = [2 9 11]
[r, c] = size(U)
clc
clear
u = [2;5;-1]
v = [-2;1;1]
w1 = u / norm(u)
disp(w1)
w2 = v / norm(v)
disp(w2)