PIKACHU LADE

lade

You are now following this Submission

%{
EXP 1 : Find Rank And Find Solution
EXP 2 : If Rank == size(b,2) {Cols}
EXP 3 :
%}
%{
EXPERIMENT 1 RANK
A = [1 1 1;
2 3 1;
1 2 3];
b = [6; 11; 14];
rankA = rank(A);
rankAug = rank([A b]);
n = size(A,2);
if rankA ~= rankAug
disp('No solution');
elseif rankA == n
disp('Unique solution exists');
x = A\b;
disp(x);
else
disp('Infinite solutions exist');
end
syms x y z
eq1 = x + y + z == 6;
eq2 = 2*x + 2*y + 2*z == 12;
eq3 = 3*x + 3*y + 3*z == 18;
sol = solve([eq1 eq2 eq3], [x y z], 'ReturnConditions', true);
disp(sol.x)
disp(sol.y)
disp(sol.z)
%}
%{
EXPERIMENT 2 LINEAR DEPENDANCE
v1 = [3;1;-4];
v2 = [2;2;-3];
v3 = [0;-4;1];
b = [v1 v2 v3];
r = rank(b);
if r == size(b,2)
fprintf('Linearly Independent (rank = %d)\n', r);
else
fprintf('Linearly Dependent (rank = %d)\n', r);
end
%}
%{
EXPERIMENT 3 BASIS AND DIM
% GIVEN VECTORS (each column is a vector)
V = [1 0 1;
0 1 1;
2 1 3]; % <-- You can replace with your vectors
% Number of vectors
num_vectors = size(V, 2);
% Dimension of the vector space (depends on ambient space ℝ^n)
space_dim = size(V, 1);
% Compute rank
r = rank(V);
% Display rank
disp(['Rank = ' num2str(r)]);
% Check if vectors form a basis
if (r == num_vectors) && (num_vectors == space_dim)
disp('The given vectors form a basis of the vector space.');
else
disp('The given vectors DO NOT form a basis of the vector space.');
end
% Vectors
v1 = [1; 0; 1];
v2 = [0; 1; 1];
% Form matrix with vectors as columns
V = [v1 v2];
% Dimension of the span = rank of V
dim = rank(V);
disp(['Dimension of the subspace spanned by the vectors = ' num2str(dim)]);
%}
%{
Practical 1: Rank of a Matrix and Solving Linear Systems
Objective:
• Compute the rank of a given matrix.
• Solve a system of linear equations using row reduction and MATLAB built-in solvers.
Tasks:
1. Compute the rank of a given matrix.
2. Solve a system of linear equations using row echelon form.
3. Verify the existence and uniqueness of solutions.
Code:
A = [2 3 5;
1 4 2;
3 2 4];
r = rank(A)
disp(['Rank of the matrix A is: ', num2str(r)]);
# Solving Ax = b
A = [2 3 5;
1 4 2;
3 2 4];
b = [7; 5; 6];
x = A \ b; % Solves Ax = b
disp('Solution x =');
disp(x);
Practice Problems:
________________________________________
Practical 2: Vector Spaces and Linear dependence/Independence of vectors
Objective:
• Check whether a given set of vectors forms a basis.
• Find the dimension of a given vector space.
Tasks:
1. Define a set of vectors and check if they are linearly independent.
2. Find the dimension of a subspace spanned by given vectors.
3. Determine if a set of vectors forms a basis for Rn\mathbb{R}^n.
Code:
# Checking for linear independence
V = [1 2 3;
2 4 6;
1 1 1];
[R, pivots] = rref(V);
disp('RREF of V is:');
disp(R);
disp('Pivot columns:');
disp(pivots);
% Check linear dependence
if length(pivots) == size(V, 2)
disp('The columns of V are linearly independent.');
else
disp('The columns of V are linearly dependent.');
end
Practice Problems:
________________________________________
Practical 3: Linear Span, Basis and Dimension
Objective:
• Check whether a given set of vectors forms a basis.
• Find the dimension of a given vector space.
Tasks:
1. Find the dimension of a subspace spanned by given vectors.
2. Determine if a set of vectors forms a basis for Rn\mathbb{R}^n.
# Checking for Basis
% GIVEN VECTORS (each column is a vector)
V = [1 0 1;
0 1 1;
2 1 3]; % <-- You can replace with your vectors
% Number of vectors
num_vectors = size(V, 2);
% Dimension of the vector space (depends on ambient space ℝ^n)
space_dim = size(V, 1);
% Compute rank
r = rank(V);
% Display rank
disp(['Rank = ' num2str(r)]);
% Check if vectors form a basis
if (r == num_vectors) && (num_vectors == space_dim)
disp('The given vectors form a basis of the vector space.');
else
disp('The given vectors DO NOT form a basis of the vector space.');
end
# Basis and dimension
% Vectors
v1 = [1; 0; 1];
v2 = [0; 1; 1];
% Form matrix with vectors as columns
V = [v1 v2];
% Dimension of the span = rank of V
dim = rank(V);
disp(['Dimension of the subspace spanned by the vectors = ' num2str(dim)]);
Practice Problems:
________________________________________
Practical 4: Linear Transformations, Composition of linear maps
Objective:
• Define a linear transformation as a matrix.
• Compute kernel and range.
• Verify the Rank-Nullity theorem.
Tasks:
1. Define a linear transformation TT and find its matrix representation.
2. Compute Kernel and Image of TT.
3. Verify the Rank-Nullity theorem.
Code:
# Composition of two linear maps
% ----- Linear map T1: R^n → R^m -----
A = [1 2;
3 4;
5 6]; % Example: 3×2 matrix
% ----- Linear map T2: R^m → R^p -----
B = [2 1 0;
0 1 1]; % Example: 2×3 matrix
% ----- Composition T2 ∘ T1 -----
C = B * A;
disp('Matrix of the composition T2 ∘ T1 is:');
disp(C);
Practice Problems:
________________________________________
Practical 5: Kernel and Range of a linear map, Rank-Nullity Theorem
Objective:
• Define a linear transformation as a matrix.
• Compute kernel and range.
• Verify the Rank-Nullity theorem.
Tasks:
4. Define a linear transformation TT and find its matrix representation.
5. Compute Kernel and Image of TT.
6. Verify the Rank-Nullity theorem.
# To compute Range and Kernel
% --- GIVEN MATRIX (TRANSFORMATION) ---
A = [2 1 3;
4 2 6;
1 0 1]; % <-- Replace with your matrix
%% ----- RANGE (COLUMN SPACE) -----
disp('RANGE (COLUMN SPACE)');
% Basis for the column space
[~, pivots] = rref(A);
range_basis = A(:, pivots);
disp('Basis for the Range (Column Space):');
disp(range_basis);
disp(['Dimension of Range = ', num2str(length(pivots))]);
%% ----- KERNEL (NULL SPACE) -----
disp('KERNEL (NULL SPACE)');
kernel_basis = null(A, 'r'); % 'r' gives rational basis if possible
disp('Basis for the Kernel (Null Space):');
disp(kernel_basis);
disp(['Dimension of Kernel = ', num2str(size(kernel_basis, 2))]);
# Checking Rank-Nullity theorem
% ----- GIVEN MATRIX -----
A = [2 1 3;
4 2 6;
1 0 1]; % <-- Replace with your matrix
%% ----- COMPUTE RANK -----
r = rank(A);
disp(['Rank(A) = ', num2str(r)]);
%% ----- COMPUTE NULLITY -----
% nullity = dimension of kernel = number of free variables
N = null(A, 'r'); % rational basis for null space
nullity = size(N, 2);
disp(['Nullity(A) = ', num2str(nullity)]);
%% ----- CHECK RANK-NULLITY THEOREM -----
n = size(A, 2); % number of columns of A
disp(['Rank(A) + Nullity(A) = ', num2str(r + nullity)]);
disp(['Number of columns (n) = ', num2str(n)]);
if r + nullity == n
disp('Rank-Nullity Theorem is VERIFIED: Rank(A) + Nullity(A) = n');
else
disp('Rank-Nullity Theorem is NOT satisfied for this matrix.');
end
Practice Problems:
________________________________________
Practical 6: Finding Eigenvalues and Eigenvectors of a matrix
Objective:
• Compute eigenvalues and eigenvectors.
• Verify Cayley-Hamilton theorem.
• Perform orthogonal diagonalization of a real symmetric matrix.
Tasks:
Code:
# Characteristic equation
A = [-2 2 -3;
2 1 -6;
-1 -2 0];
% Define symbolic variable
syms k
% Compute characteristic polynomial p(k) = det(A - k*I)
p = det(A - k*eye(size(A)));
disp('Characteristic Polynomial p(k) =');
pretty(p)
% Characteristic equation
disp('Characteristic Equation:');
pretty(p == 0)
# Eigenvalue and Eigenvector
A = [-2 2 -3;
2 1 -6;
-1 -2 0];
e_vals = eig(A);
disp('Eigenvalues:');
disp(e_vals);
% Step 2: Compute eigenvectors manually using (A - kI)X = 0
disp('Eigenvectors (solving (A - kI)X = 0):');
for i = 1:length(e_vals)
k = e_vals(i); % eigenvalue
M = A - k * eye(size(A)); % (A - kI)
% Solve null space of (A - kI)
X = null(M, 'r'); % rational basis → cleaner vectors
fprintf('Eigenvector for k = %.4f :\n', k);
disp(X);
end
Practice Problems:
________________________________________
Practical 7: Diagonalization of a matrix
Objective:
• Compute eigenvalues and eigenvectors.
• Verify Cayley-Hamilton theorem.
• Perform orthogonal diagonalization of a real symmetric matrix.
Tasks:
Code:
# Characteristic equation
A = [-2 2 -3;
2 1 -6;
-1 -2 0];
% Define symbolic variable
syms k
% Compute characteristic polynomial p(k) = det(A - k*I)
p = det(A - k*eye(size(A)));
disp('Characteristic Polynomial p(k) =');
pretty(p)
% Characteristic equation
disp('Characteristic Equation:');
pretty(p == 0)
# Eigenvalue and Eigenvector
A = [-2 2 -3;
2 1 -6;
-1 -2 0];
e_vals = eig(A);
disp('Eigenvalues:');
disp(e_vals);
% Step 2: Compute eigenvectors manually using (A - kI)X = 0
disp('Eigenvectors (solving (A - kI)X = 0):');
for i = 1:length(e_vals)
k = e_vals(i); % eigenvalue
M = A - k * eye(size(A)); % (A - kI)
% Solve null space of (A - kI)
X = null(M, 'r'); % rational basis → cleaner vectors
fprintf('Eigenvector for k = %.4f :\n', k);
disp(X);
end
Practice Problems:
________________________________________
Practical 8: Exact equations, Equations reducible to exact equations using integrating factors
Objective:
• Solve exact differential equations.
• Solve Bernoulli equations using Sage.
• Plot orthogonal trajectories.
Tasks:
Code:
syms y(x)
% Define the differential equation
ode = diff(y, x) == x*y + y^2*exp((-x^2)/2)*log(x);
% Solve the ODE symbolically
ySol = dsolve(ode);
disp('General solution of the ODE:');
disp(ySol);
Practice Problems:
________________________________________
Practical 9: Linear equations, Bernoulli equation, Orthogonal trajectories
Objective:
• Solve exact differential equations.
• Solve Bernoulli equations using Sage.
• Plot orthogonal trajectories.
Tasks:
Code:
syms y(x)
% Define the differential equation
ode = diff(y, x) == x*y + y^2*exp((-x^2)/2)*log(x);
% Solve the ODE symbolically
ySol = dsolve(ode);
disp('General solution of the ODE:');
disp(ySol);
Practice Problems:
________________________________________
Practical 10: Higher order Ordinary Differential Equations
Objective:
• Solve higher-order linear differential equations with constant coefficients.
• Use variation of parameters and undetermined coefficients.
• Solve Euler-Cauchy equations.
Tasks:
Code:
syms y(x)
% Define the differential equation
ode = diff(y, x, 2) + 4*diff(y, x) + 4*y == sin(x);
% Solve the ODE symbolically
ySol = dsolve(ode);
disp('General solution of the ODE:'); disp(ySol);
Practice Problems:
________________________________________
Practical 11: Operator method, Undetermined coefficients
Objective:
• Solve higher-order linear differential equations with constant coefficients.
• Use variation of parameters and undetermined coefficients.
• Solve Euler-Cauchy equations.
Tasks:
Code:
syms y(x)
% Define the differential equation
ode = diff(y, x, 2) + 4*diff(y, x) + 4*y == sin(x);
% Solve the ODE symbolically
ySol = dsolve(ode);
disp('General solution of the ODE:'); disp(ySol);
Practice Problems:
________________________________________
Practical 12: Power Series Solutions
Objective:
• Find power series solutions of differential equations.
• Implement solutions for Legendre and Bessel functions.
Tasks:
Code:
syms f(x)
% Define the differential equation
ode = x^2*diff(f, x, 2) + x*diff(f, x) - (x^2 + 1)*f == 0;
% Solve the ODE symbolically
fSol = dsolve(ode);
disp('General solution of the ODE:');
disp(fSol);
Practice Problems:
________________________________________
Practical 13: Formation and Classification of PDEs
Objective:
• Form partial differential equations from given conditions.
• Classify PDEs as elliptic, parabolic, or hyperbolic.
Tasks:
Code:
clc
% PDE: A(x,y)*u_xx + B(x,y)*u_xy + C(x,y)*u_yy = 0
syms x y A(x,y) B(x,y) C(x,y)
% Example coefficient definitions:
% (You can change them for your PDE)
A(x,y) = sin(x)^2; % coefficient of u_xx
B(x,y) = sin(2*x); % coefficient of u_xy
C(x,y) = cos(x)^2; % coefficient of u_yy
% Compute discriminant
D = simplify( B(x,y)^2 - 4*A(x,y)*C(x,y) );
fprintf('\nDiscriminant is:\n');
disp(D);
% Classify the PDE
if isAlways(D < 0)
disp('PDE is Elliptic')
elseif isAlways(D == 0)
disp('PDE is Parabolic')
elseif isAlways(D > 0)
disp('PDE is Hyperbolic')
else
disp('Type changes depending on x,y (Mixed type PDE)')
end
Practice Problems:
________________________________________
Practical 14: Separation of variables method
Objective:
• Solve PDEs using direct integration.
• Use the separation of variables method.
Tasks:
Code:
%% Step 0: Clear workspace
clear; clc;
%% Step 1: Declare symbols
syms x y k C1 C2
%% Step 2: Assume separable solution u(x,y) = X * Y
syms X Y
u = X * Y; % treat X and Y as symbolic constants (will solve as functions below)
%% Step 3: Express derivatives manually
% Assume X = X(x), Y = Y(y) -> X' = dX/dx, Y' = dY/dy
syms dX dY
ux = dX * Y;
uy = X * dY;
%% Step 4: PDE substitution u_x + u_y = 0
pde_eq = ux + uy;
disp('PDE after substitution:')
pretty(pde_eq)
%% Step 5: Separate variables
eq_sep = simplify(pde_eq / (X*Y));
disp('Separated form:')
pretty(eq_sep)
%% Step 6: Set each part equal to constant k
% X'/X = k => dX = k*X
% Y'/Y = -k => dY = -k*Y
disp('ODEs for manual separation:')
disp('dX/dx = k*X')
disp('dY/dy = -k*Y')
%% Step 7: Solve ODEs symbolically
Xsol = C1*exp(k*x);
Ysol = C2*exp(-k*y);
%% Step 8: General separable solution
u_general = simplify(Xsol * Ysol);
disp('General separable solution:')
pretty(u_general)
%% Step 9: Apply initial condition u(x,0) = exp(-x)
% u(x,0) = C1*C2*exp(k*x) = exp(-x) => k = -1, C1*C2 = 1
k_val = -1;
C1C2_val = 1; % product of constants
u_final = subs(u_general, [k, C1*C2], [k_val, C1C2_val]);
u_final = simplify(u_final);
disp('Final solution u(x,y) =')
pretty(u_final)
Ques 1
disp('Q1')
A = [8 -8 -2;
4 -3 -2;
3 -4 1];
eigVals = eig(A);
disp('Eigenvalues:')
disp(eigVals)
[V,D] = eig(A);
disp('Eigenvector matrix V (columns are eigenvectors):')
disp(V)
disp('Diagonal matrix D:')
disp(D)
eigValsR = round(eigVals,6);
uniqueVals = unique(eigValsR);
disp('Algebraic & Geometric Multiplicity:')
for i = 1:length(uniqueVals)
lambda = uniqueVals(i);
alg = sum(eigValsR == lambda);
geo = size(null(A - lambda*eye(size(A))),2);
fprintf('lambda = %.4f , algebraic multiplicity = %d , geometric multiplicity
= %d\n', lambda, alg, geo);
End
%% Ques 1
disp("Question 1");
clc;
clear;
syms x y
% Define M and N
M = 2*x*y*cos(x^2) - 2*x*y + 1;
N = sin(x^2) - x^2;
% Step 1: Check exactness
dMdy = diff(M,y);
dNdx = diff(N,x);
disp('dM/dy = ')
disp(dMdy)
disp('dN/dx = ')
disp(dNdx)
if simplify(dMdy - dNdx) == 0
disp('The equation is EXACT')
else
disp('The equation is NOT exact')
end
% If not exact,find an integrating factor
expr = simplify((dMdy - dNdx)/N);
disp('Expression for Integrating Factor (if function of x only):');
pretty(expr)
mu = exp(int(expr,x)); % integrating factor
mu = simplify(mu)
% Multiply equation by integrating factor
M1 = simplify(mu*M);
N1 = simplify(mu*N);
% Verify new equation is exact
if simplify(diff(M1, y) - diff(N1,x)) == 0
disp('Transformed equation is Exact');
end
% Final Solution is
Cx = int(M1,x);
Cy = diff(Cx,y);
g = int(N1 - Cy, y);
C = simplify(Cx + g);
disp('General Solution:')
disp(C)
%% Question 2
disp("Question 2");
clc;
clear;
syms x y
% Define M and N
M = 2*y;
N = 2*x*log(x) - x*y;
% Step 1: Check exactness
dMdy = diff(M,y);
dNdx = diff(N,x);
disp('dM/dy = ')
disp(dMdy)
disp('dN/dx = ')
disp(dNdx)
if simplify(dMdy - dNdx) == 0
disp('The equation is EXACT')
else
disp('The equation is NOT exact')
end
% If not exact,find an integrating factor
expr = simplify((dMdy - dNdx)/N);
disp('Expression for Integrating Factor (if function of x only):');
pretty(expr)
mu = exp(int(expr,x)); % integrating factor
mu = simplify(mu)
% Multiply equation by integrating factor
M1 = simplify(mu*M);
N1 = simplify(mu*N);
% Verify new equation is exact
if simplify(diff(M1, y) - diff(N1,x)) == 0
disp('Transformed equation is Exact');
end
% Final Solution is
Cx = int(M1,x);
Cy = diff(Cx,y);
g = int(N1 - Cy, y);
C = simplify(Cx + g);
disp('General Solution:')
disp(C)
%Sample Question
clc; clear;
disp('Sample Question');
syms k
A = [-2 2 -3;
2 1 -6;
-1 -2 0];
I = eye(size(A));
% Characteristic polynomial
charPoly = expand(det(A - k*I));
disp('Characteristic polynomial:');
disp(charPoly)
disp('Characteristic Equation:');
charEq = charPoly == 0;
disp(charEq)
% Solve characteristic equation
eigVals = solve(charPoly == 0, k);
disp('Eigenvalues:');
disp(eigVals)
evals=eig(A);
disp('Eigenvalues:');
disp(evals)
[V, D] = eig(A);
disp('Eigenvector matrix V (columns are eigenvectors):');
disp(V)
% Question.1
disp('Q1');
syms k
A = [3 1 4;
0 2 6;
0 0 5];
I = eye(size(A));
% Characteristic polynomial
charPoly = expand(det(A - k*I));
disp('Characteristic polynomial:');
disp(charPoly)
disp('Characteristic Equation:');
charEq = charPoly == 0;
disp(charEq)
% Solve characteristic equation
eigVals = solve(charPoly == 0, k);
disp('Eigenvalues:');
disp(eigVals)
evals=eig(A);
disp('Eigenvalues:');
disp(evals)
[V, D] = eig(A);
disp('Eigenvector matrix V (columns are eigenvectors):');
disp(V)
% 2. RANGE AND KERNEL
clc; clear;
syms x y z real
% Define equations for kernel
eq1 = x - y == 0;
eq2 = x + y == 0;
eq3 = 2*x - 3*y == 0;
% Solve symbolically
S = solve([eq1, eq2, eq3], [x, y, z], 'ReturnConditions', true);
disp('Kernel solution structure:');
disp(S)
kernel_vec = [S.x; S.y; S.z];
disp('Kernel vector (parametric):');
disp(kernel_vec)
num_params = length(S.parameters);
fprintf('Nullity(T) = %d\n', num_params);
% --- MATRIX FORM ---
A = [1 -1 0;
1 1 0;
2 -3 0];
%% ----- RANGE (COLUMN SPACE) -----
disp('RANGE (COLUMN SPACE)');
[~, pivots] = rref(A);
range_basis = A(:, pivots);
disp('Basis for the Range (Column Space):');
disp(range_basis);
disp(['Dimension of Range = ', num2str(length(pivots))]);
%% ----- KERNEL (NULL SPACE) -----
disp('KERNEL (NULL SPACE)');
kernel_basis = null(A, 'r');
disp('Basis for the Kernel (Null Space):');
disp(kernel_basis);
disp(['Dimension of Kernel = ', num2str(size(kernel_basis, 2))]);
%}

Cite As

Avdhoot (2026). PIKACHU LADE (https://in.mathworks.com/matlabcentral/fileexchange/183632-pikachu-lade), MATLAB Central File Exchange. Retrieved .

Tags

Add Tags

Add the first tag.

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0