Julia Exp7
Julia Exp7
Julia Exp7
Theory:
Code:
using LinearAlgebra
function main()
# Example matrix
A = [1.0 2.0 3.0;
4.0 5.0 6.0;
7.0 8.0 10.0]
println(A)
println()
# Determinant
det_A = det(A)
println("Determinant of A:")
println(det_A)
println()
# Inverse
inv_A = inv(A)
println("Inverse of A:")
println(inv_A)
println()
# Rank
rank_A = rank(A)
println("Rank of A:")
println(rank_A)
println()
println()
# Diagonal elements
diag_A = diag(A)
println("Diagonal elements of A:")
println(diag_A)
println()
# Euclidean norm
norm_A = norm(A)
println("Euclidean norm of A:")
println(norm_A)
println()
Theory:
Code:
m, n = size(A)
C = zeros(m, n) # Initialize a matrix to store the result
for i in 1:m
for j in 1:n
C[i, j] = A[i, j] + B[i, j]
end
end
return C
end
m, n = size(A)
D = zeros(m, n) # Initialize a matrix to store the result
for i in 1:m
for j in 1:n
return D
end
# Example usage
# Define two matrices A and B
A = [1 2 3;
4 5 6;
7 8 9]
B = [9 8 7;
6 5 4;
3 2 1]
# Perform addition
C = matrix_addition(A, B)
println("Result of addition:")
println(C)
# Perform subtraction
D = matrix_subtraction(A, B)
println("\nResult of subtraction:")
println(D)