We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
8a.
Develop a Julia program to evaluate expressions consisting of rational, irrational number and floatingpoint numbers)
# Function to evaluate an expression with rational numbers
function evaluate_expression_rn() # Define rational numbers x = 1 // 2 # Represents 1/2 y = 3 // 4 # Represents 3/4 # Define an expression with rational numbers expr = 2 * x + 3 * y # Evaluate the expression result = 2 * x + 3 * y return result end
# Function to evaluate an expression with irrational numbers
function evaluate_expression_irn() # Define irrational number sqrt2 = sqrt(2) # Square root of 2 # Define an expression with irrational number expr = sqrt2 + 3.14 # Evaluate the expression result = sqrt2 + 3.14 return result end
# Function to evaluate an expression with floating-point numbers
function evaluate_expression_fpn() # Define floating-point numbers x = 3.5 y = 2.25 # Define an expression with floating-point numbers expr = 2.0 * x + 1.5 * y # Evaluate the expression result = 2.0 * x + 1.5 * y return result end
# Main function to run the evaluation and display the result
function main() r1 = evaluate_expression_rn() println("Result of the expression with rational numbers: ", r1) r2 = evaluate_expression_irn() println("Result of the expression with irrational numbers: ", r2) r3 = evaluate_expression_fpn() println("Result of the expression with floating-point numbers: ", r3) end
# Call the main function to execute the program
main() 8b. Develop a Julia program to determine the following properties of a matrix: determinant, inverse, rank, upper & lower triangular matrix, diagonal elements, Euclidean norm and Square Root of a Matrix using LinearAlgebra # Function to determine matrix properties function matrix_properties(A) # Determinant det_A = det(A) # Inverse inv_A = inv(A) # Rank rank_A = rank(A) # Upper triangular matrix upper_triangular = UpperTriangular(A) # Lower triangular matrix lower_triangular = LowerTriangular(A) # Diagonal elements diagonal_elements = diag(A) # Euclidean norm norm_A = norm(A) # Square root of matrix # sqrt_A = sqrtm(A) return det_A, inv_A, rank_A, upper_triangular, lower_triangular, diagonal_elements, norm_A end # Main function to determine and print matrix properties function main() # Example matrix A = [1.0 2.0 3.0; 4.0 5.0 6.0; 7.0 8.0 10.0] println("Matrix A:") println(A) println() # Determine properties det_A, inv_A, rank_A, upper_triangular, lower_triangular, diagonal_elements, norm_A = matrix_properties(A) # Print results println("Determinant of A: ", det_A) println("Inverse of A:") println(inv_A) println("Rank of A: ", rank_A) println("Upper triangular matrix: ", upper_triangular) println("Lower triangular matrix: ", lower_triangular) println("Diagonal elements of A: ", diagonal_elements) println("Euclidean norm of A: ", norm_A) # println("Square root of A:") # println(sqrt_A) end # Call the main function to execute the program main()