Assignment No.
01
Write a program to find angle between two vectors and
check orthogonality
ALGORITHM
Step 1: Start
Step 2: Input vector A = [a1, a2, ..., an]
Step 3: Input vector B = [b1, b2, ..., bn]
Step 4: Check if length of A and B are equal
→ If not, display error and stop
Step 5: Compute dot product:
dot_prod = A · B
Step 6: Compute magnitudes:
mag_A = ||A||, mag_B = ||B||
Step 7: Compute angle in radians:
angle_rad = acos(dot_prod / (mag_A * mag_B))
Step 8: Convert to degrees:
angle_deg = angle_rad × (180 / π)
Step 9: Display angle
Step 10: Check orthogonality:
If abs(dot_prod) < 1e-10, then
→ Print “Vectors are orthogonal”
Else
→ Print “Vectors are not orthogonal”
Step 11: Stop
Assignment No. 02
Write a program to find the rank and nullity of a matrix
through its row reduced echelon form
ALGORITHM:
Step 1: Start
Step 2: Input the matrix A of size m × n.
Step 3: Compute the RREF (Row Reduced Echelon Form) of matrix A,
denote it by R.
Step 4: Initialize rank = 0.
Step 5: For each row in R:
• If the row is not all zeros, increment rank by 1.
Step 5: Compute nullity as:
nullity = n − rank,
where n is the number of columns in the matrix.
Step 6: Output:
• The RREF of the matrix
• The rank
• The nullity
Step 7 : End
Assignment No. 03
Write a program to check whether the given vector is in
the span of a set of vectors
ALGORITHM:
Step 1: Start
Step 2: Input
• Matrix A of size m×n (columns represent the given set of
vectors)
• Vector b of size m×1.
Step 3: Solve the system A⋅x=b using the least squares method:
x=A\b
Step 4: Compute the residual (error vector):
r=A⋅x−b.
Step 5: Compute the norm of the residual:
error=∥r∥=∥A⋅x−b∥.
Step 6: Set a small tolerance value,
e.g., tolerance=10-10.
Step 7: Compare the error with the tolerance:
• If error<tolerance:
Output: “The vector b is in the span of the set of vectors.”
• Else:
Output: “The vector b is NOT in the span of the set of vectors.”
Stepm 8: End.
Assignment No. 04
Write a Program to discuss the nature of consistency for system of linear
equations
ALGORITHM:
Assignment No. 05
Write a MATLAB Program to verify linear dependency of a set of vectors
ALGORITHM: