0% found this document useful (0 votes)
11 views54 pages

Numsol Merge Files

Uploaded by

Angelica Cabello
Copyright
© © All Rights Reserved
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
0% found this document useful (0 votes)
11 views54 pages

Numsol Merge Files

Uploaded by

Angelica Cabello
Copyright
© © All Rights Reserved
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/ 54

Lecture Series 1.

Introduction to Numerical Analysis

Definition of Numerical Solutions

Numerical solutions are approximate methods for solving mathematical problems that
cannot be easily solved using exact, analytical methods. These solutions involve iterative
procedures or algorithms to compute an answer to a desired level of accuracy.

Difference Between Analytical and Numerical Solutions

• Analytical Solutions: These are exact solutions derived using algebraic manipulations and
closed-form expressions. For example, solving a quadratic equation using the quadratic
formula.

• Numerical Solutions: These involve approximations and computational techniques to find


solutions. For example, using the Newton-Raphson method to find the root of a non-linear
equation.

Importance in Solving Real-World Problems

Numerical solutions are crucial for tackling complex real-world problems that are difficult or
impossible to solve analytically. Such problems often involve intricate equations or large systems
that do not have straightforward solutions.

Applications in Various Fields

1. Engineering:

Structural analysis using finite element methods.

Fluid dynamics simulations using computational fluid dynamics (CFD).

Transient analysis in electrical circuits.

2. Finance:

Pricing complex financial derivatives using Monte Carlo simulations.

Risk assessment and management through numerical optimization.

Types of Numerical Solutions

Root-finding methods (e.g., Bisection method, Newton-Raphson method).


Interpolation and extrapolation (e.g., Lagrange interpolation, Newton's divided differences).

Numerical integration and differentiation (e.g., Trapezoidal rule, Simpson's rule).

Solving systems of linear equations (e.g., Gaussian elimination, LU decomposition).

Numerical solutions of ordinary differential equations (e.g., Euler's method, Runge-Kutta


methods).

Error Analysis

Objective:

1. Understand the types and sources of errors in numerical computations.

2. Learn how to compute errors and distinguish between absolute and true errors.

3. Learn methods to minimize errors and ensure the accuracy of numerical solutions.

Types of Errors

1. Truncation Error:

Errors that arise from approximating a mathematical process.

Example: Approximating the derivative of a function using finite differences.

2. Round-off Error:

Errors due to the finite precision of numerical computations.

Example: Errors introduced when representing numbers in a computer.

Sources of Errors

Approximation of Mathematical Functions:

Using series expansions or finite differences.

Finite Precision of Computer Arithmetic:

Limited number of digits to represent numbers, leading to rounding.

Propagation of Errors through Iterative Processes:

Errors can accumulate in iterative algorithms.


Measuring Errors

1. Absolute Error:

The absolute difference between the true value and the approximate value.

𝐴𝑏𝑠𝑜𝑙𝑢𝑡𝑒 𝐸𝑟𝑟𝑜𝑟 (𝑒𝑎𝑏𝑠 ) = |𝑥𝑡𝑟𝑢𝑒 − 𝑥𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒 |

2. Relative Absolute Error:

The absolute error divided by the true value, often expressed as a percentage.

|𝑥𝑡𝑟𝑢𝑒 − 𝑥𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒 |
𝑅𝑒𝑙𝑎𝑡𝑖𝑣𝑒 𝐸𝑟𝑟𝑜𝑟 (𝑒𝑟 ) = 𝑥100%
|𝑥𝑡𝑟𝑢𝑒 |
3. True Error:

The difference between the exact mathematical value and the approximate value.

𝑇𝑟𝑢𝑒 𝐸𝑟𝑟𝑜𝑟 (𝑒𝑡 ) = 𝑥𝑡𝑟𝑢𝑒 − 𝑥𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒

4. Approximate Error:

The difference between successive approximations.

𝐴𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒 𝐸𝑟𝑟𝑜𝑟 (𝑒𝑎 ) = 𝑥𝑐𝑢𝑟𝑟𝑒𝑛𝑡 − 𝑥𝑝𝑟𝑒𝑣𝑖𝑜𝑢𝑠

5. Absolute Approximate Error:

The difference between successive approximations.

𝐴𝑏𝑠𝑜𝑙𝑢𝑡𝑒 𝐴𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒 𝐸𝑟𝑟𝑜𝑟 (𝑒𝑎𝑏𝑠 ) = |𝑥𝑐𝑢𝑟𝑟𝑒𝑛𝑡 − 𝑥𝑝𝑟𝑒𝑣𝑖𝑜𝑢𝑠 |

5. Relative Approximate Error:

The approximate error divided by the current value, often expressed as a


percentage.

|𝑥𝑐𝑢𝑟𝑟𝑒𝑛𝑡 − 𝑥𝑝𝑟𝑒𝑣𝑖𝑜𝑢𝑠 |
𝑅𝑒𝑙𝑎𝑡𝑖𝑣𝑒 𝐴𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒 𝐸𝑟𝑟𝑜𝑟 (𝑒𝑟 ) = 𝑥100%
|𝑥𝑐𝑢𝑟𝑟𝑒𝑛𝑡 |

Example Calculations

Example 1: Absolute and Relative Error

Given:

True value = 3.14159265

Approximate value = 3.14


Example 2: True Error

Given:

True value = 2.7182818

Approximate value = 2.72

Example 3. Approximate and Relative

Suppose we are using an iterative method to find the root of an equation, and we have the
following successive approximations:

Previous value = 2.718

Current value = 2.7183


Methods to Minimize Errors

1. Using Higher Precision Arithmetic:

Employing data types with more significant digits.

2. Choosing Appropriate Numerical Methods:

Selecting methods that reduce truncation and round-off errors.

3. Controlling the Number of Iterations in Iterative Methods:

Balancing between accuracy and computational cost.

4. Error Estimation and Adaptive Methods:

Using error estimates to adjust step sizes in numerical methods dynamically.

Practical Tips for Error Analysis

Avoid Subtraction of Nearly Equal Numbers:

Can lead to significant loss of precision.

Scale Problems Appropriately:

Scaling can reduce the impact of round-off errors.

Use Built-in Functions Carefully:

Be aware of the precision and limitations of built-in numerical functions.


LAB01. Introduction to Scilab with Functions and Scripts

Objectives:

1. Familiarize students with the Scilab environment.

2. Perform basic computations.

3. Write and execute simple scripts.

4. Define and use functions.

5. Utilize trigonometric, exponential, and logarithmic functions.

6. Plot data and functions.

Materials Needed:

Computers with Scilab installed.

Lab instructions (provided below).

Lab Outline:

1. Introduction to Scilab (30 minutes)

Opening Scilab and navigating the environment.

Basic operations and commands.

Variables and data types.

2. Basic Computations and Scripts (40 minutes)

Performing arithmetic operations.

Writing and running simple scripts.

3. Creating and Using Functions (40 minutes)

Defining functions.

Using functions in scripts.

Conditional statements and loops.

Trigonometric, exponential, and logarithmic functions.


4. Plotting Data (40 minutes)

Basic plotting commands.

Customizing plots (titles, labels, legends).

Plotting functions and data.

5. Practical Exercise (30 minutes)

A guided exercise involving the creation of a script that uses functions and plotting.

Detailed Instructions:

1. Introduction to Scilab (30 minutes)

Starting Scilab:

Open Scilab from your applications menu.

Familiarize yourself with the console, editor, and workspace.

Basic Commands:

--> // Simple arithmetic

--> a = 5 + 3;

--> b = 10 - 2;

--> c = 4 * 7;

--> d = 20 / 4;

--> // Displaying results

--> disp(a);

--> disp(b);

--> disp(c);

--> disp(d);

Variables and Data Types:


--> // Scalar

--> x = 10;

--> y = 5

--> // Vector

--> v = [1, 2, 3, 4];

--> v = [2, -1, 5, 0]

--> // Display variables

--> disp(x);

--> disp(v);

2. Basic Computations and Scripts (40 minutes)

Performing Arithmetic Operations:

--> // Arithmetic operations

--> x = 10;

--> y = 20;

--> sum = x + y;

--> difference = x - y;

--> product = x * y;

--> quotient = x / y;

--> // Display results

--> disp(sum);

--> disp(difference);

--> disp(product);

--> disp(quotient);

Creating and Running Scripts:


Open the Scilab editor or launch Scinotes.

Write the following script and save it as “basic_operations”:

// basic_operations

x = 10;

y = 20;

sum = x + y;

difference = x - y;

product = x * y;

quotient = x / y;

disp(sum);

disp(difference);

disp(product);

disp(quotient);

Run the script from the console using F5

3. Creating and Using Functions (40 minutes)

Defining Functions:

--> function y = myfunction(x)

--> y = x^2 + 2*x + 1;

--> endfunction

--> // Using the function

--> result = myfunction(3);

--> disp(result);

Using Functions in Scripts:

Create a script “use_function”:

// use_function

function y = myfunction(x)
y = x^2 + 2*x + 1;

endfunction

result1 = myfunction(2);

result2 = myfunction(5);

disp(result1);

disp(result2);

Conditional Statements and Loops:

// Conditional statement

x = 5;

if x > 0 then

disp('x is positive');

else

disp('x is non-positive');

end

// Loop

for i = 1:5

disp(i);

end

Trigonometric, Exponential, and Logarithmic Functions:

--> // Trigonometric functions

--> theta = %pi / 4; // 45 degrees

--> sin_theta = sin(theta);

--> cos_theta = cos(theta);

--> tan_theta = tan(theta);


--> disp(sin_theta);

--> disp(cos_theta);

--> disp(tan_theta);

--> // Exponential and logarithmic functions

--> e = exp(1); // Euler's number

--> exp_val = exp(2); // e^2

--> log_val = log(2); // Natural logarithm of 2

--> log10_val = log10(100); // Logarithm base 10 of 100

--> disp(e);

--> disp(exp_val);

--> disp(log_val);

--> disp(log10_val);

4. Plotting Data (40 minutes)

Basic Plotting:

--> x = 0:0.1:10;

--> y = sin(x);

--> plot(x, y);

Customizing Plots:

--> plot(x, y);

--> title('Sine Wave');

--> xlabel('x-axis');

--> ylabel('y-axis');

--> legend('sin(x)');
Plotting Multiple Functions:

--> y1 = sin(x);

--> y2 = cos(x);

--> plot(x, y1, 'r', x, y2, 'b');

--> legend('sin(x)', 'cos(x)');

5. Practical Exercise (30 minutes)

Guided Exercise:

Create a script that:

1. Defines a function that takes a vector as input and returns the vector with each
element squared.

2. Uses trigonometric, exponential, and logarithmic functions.

3. Plots the original and transformed vectors.

Solution:

// Define a function

function y = square_vector(x)

y = x .^ 2;

endfunction

// Use the function

v = 0:0.1:5;

squared_v = square_vector(v);

disp(squared_v);

// Trigonometric, exponential, and logarithmic functions

sin_v = sin(v);

exp_v = exp(v);

log_v = log(v + 1); // log(0) is undefined, so we use log(v + 1)


// Plotting

plot(v, v, 'r', v, squared_v, 'b', v, sin_v, 'g', v, exp_v, 'm', v, log_v, 'c');

title('Various Functions');

xlabel('x-axis');

ylabel('y-axis');

legend('Original', 'Squared', 'sin(x)', 'exp(x)', 'log(x + 1)');


LAB02. Introduction to Matrices

In this tutorial, you will learn how to use SCILAB to perform basic matrix operations, such as
entering matrices, finding their sizes, adding, subtracting, and multiplying them. You will also learn
how to use Scinote, a web-based notebook for SCILAB, to display your results.

To enter a matrix in SCILAB, you can use square brackets [ ] and separate the elements by spaces or
commas. To start a new row, you can use a semicolon ; or a new line. For example, to enter the
matrix A = [ 1 2 3 ; 4 5 6 ], you can type:

-->A = [1 2 3; 4 5 6]

or

-->A = [1, 2, 3

4, 5, 6]

To find the size of a matrix, you can use the size function, which returns the number of rows and
columns as a vector. For example, to find the size of the matrix A, you can type:

-->size(A) // The first number indicates the row and the second number indicates the column.

ans = [1x2 double]

2. 3.

To add or subtract two matrices, they must have the same size. You can use the + or - operators to
perform element-wise addition or subtraction. For example, to add the matrices C and D, you can
type:

-->C = [ 7 ; 8 ; 9 ]

-->D = [ 10 11 ]

-->C + D

Operator +: Wrong dimensions for operation [3x1] + [1x2], same dimensions expected.

-->A = [1 2 3; 4 5 6]

-->B = [-1 1 5; 2 -3 4]

-->A+B

ans = [2x3 double]

0. 3. 8.

6. 2. 10.

-->A-B
ans =

2. 1. -2.

2. 8. 2.

To multiply two matrices, the number of columns of the first matrix must equal the number of rows
of the second matrix. You can use the * operator to perform matrix multiplication. For example, to
multiply the matrices A and B, you can type:

-->A = [1 2 3; 4 5 6]

-->B = [-1 1 5; 2 -3 4]

-->A*B

Operator *: Wrong dimensions for operation [2x3] * [2x3].

-->A = [1 2 3; 4 5 6]

-->B = [ -1; 0 ; 1 ]

-->A * B

ans = [2x1 double]

2.

2.

For this part, create a new scinotes file and type the following. Run and save the file. See the results
in the console.

// save this file as arithmetic_operation1

A = [2 -1 0; 3 1 2; 4 5 -1];

B = [1 2 3; 4 5 6; 7 8 9];

disp(A)

disp(B) // display the matrix

// perform and display the subtraction of the matrices

disp('The subtraction of A and B is:')

disp(A - B)

// perform and display the multiplication of the matrices

disp('The multiplication of A and B is:')


disp(A * B)

// from here, save and run your scinotes file for the results, then exit file for the results
shown on command console.

You can use the input function to accept the elements of a matrix from the user. The input function
takes a string as an argument and displays it as a prompt. You can also specify the type of the input
by using the 'string', 'double' or 'integer' keywords.

For example, to ask the user for a 3x3 matrix, you can use the following code:

// This is a new scinotes file and save this file as arithmetic_operation2

A = [] // initialize an empty matrix

// Loop through each element and prompt the user to input values

disp("Enter the elements of the matrix:");

for i = 1:m

for j = 1:n

A(i, j) = input("Enter element (" + string(i) + "," + string(j) + "): ");

end

end

disp(A) // display the matrix

// Your scinotes file for arithmetic_operation2 ends here.

You can repeat the same process for another matrix, say B, and then display the result of any
operation you want.

For example, to display the result of A + B, you can type:

disp(A + B) // display the sum of the matrices

// Open the previous file arithmetic_operations2

// Save the file as arithmetic_operations3

// Add the following program at the end of the existing program, and when done, run and
save the file.
// create a matrix B with the same dimensions as A

B = zeros(3,3) // initialize a 3x3 matrix of zeros

// Loop through each element and prompt the user to input values

disp("Enter the elements of the matrix:");

for i = 1:m

for j = 1:n

B(i, j) = input("Enter element (" + string(i) + "," + string(j) + "): ");

end

end

disp(B) // display the matrix

// perform and display the addition of the matrices

disp(A + B) // display the sum of the matrices

// perform and display the subtraction of the matrices

disp('The subtraction of A and B is:')

disp(A - B)

// perform and display the multiplication of the matrices

disp('The multiplication of A and B is:')

disp(A * B)

This laboratory activity ends here. Perform the following lab exercises using the lecture on
SCILAB above. You may use SCILAB Notes or use the command console for the execution of this
exercises.

If you choose to place it in SCINOTES, you may combine the exercises from numbers 1-5, ‘a’
to ‘j’ into a single file and save it as lab_exercises2. Go to command console and copy and save the
output of this lab_exercises2 in a document file, and label it as lab_exercises2_output.

If you choose to do the activity in the command console, go to command console and copy
and save all the commands and output of this lab exercises in a document file, and label it as
lab_exercises2_output.

Lab Exercises

1. Identify the number of rows and columns in each matrix:


(a) A=[1 2 3;4 5 6]
(b) B = [ -1 0 1 ]
(c) C=[7;8;9]
(d) D = [ 10 11 ].
(e) E = [ 2 4 5; 1 -3 2 ; 4 7 -3]
(f) F = [ -2 3 6 ; 0 2 4]
(g) G = [ 4 0 1; 2 1 -2 ; 1 1 2]
(h) H = [ -1 ; 3 ; 4 ]
(i) I = [ 0 -2 13 ; 1 2 -4 ]
(j) J = [ -1 -2 1 ; 2 -1 3 ]

2. Determine the size of the given matrices.


(a) A = [ 1 2 3 ; 4 5 6 ]
(b) B = [ -1 0 1 ]
(c) C = [ 7 ; 8 ; 9 ]
(d) D = [ 10 11 ].
(e) E = [ 2 4 5; 1 -3 2 ; 4 7 -3]
(f) F = [ -2 3 6 ; 0 2 4]
(g) G = [ 4 0 1; 2 1 -2 ; 1 1 2]
(h) H = [ -1 ; 3 ; 4 ]
(i) I = [ 0 -2 13 ; 1 2 -4 ]
(j) J = [ -1 -2 1 ; 2 -1 3 ]

3. Add the following matrices if possible:


(a) A + B
(b) A + C
(c) B + D
(d) C + D
(e) A + I
(f) I + J
(g) A + F
(h) E + G
(i) C + H
(j) B + H
4. Subtract the following matrices if possible:
(a) A + B
(b) A + C
(c) B + D
(d) C + D
(e) A + I
(f) I + J
(g) A + F
(h) E + G
(i) C + H
(j) B + H

5. Multiply the following matrices if possible:


(a) AB
(b) AC
(c) BA
(d) CA
(e) BC
(f) CB
(g) CD
(h) DC
(i) GE
(j) IC
LAB02. Introduction to Matrices

In this tutorial, you will learn how to use SCILAB to perform basic matrix operations, such as
entering matrices, finding their sizes, adding, subtracting, and multiplying them. You will also learn
how to use Scinote, a web-based notebook for SCILAB, to display your results.

To enter a matrix in SCILAB, you can use square brackets [ ] and separate the elements by spaces or
commas. To start a new row, you can use a semicolon ; or a new line. For example, to enter the
matrix A = [ 1 2 3 ; 4 5 6 ], you can type:

-->A = [1 2 3; 4 5 6]

or

-->A = [1, 2, 3

4, 5, 6]

To find the size of a matrix, you can use the size function, which returns the number of rows and
columns as a vector. For example, to find the size of the matrix A, you can type:

-->size(A) // The first number indicates the row and the second number indicates the column.

ans = [1x2 double]

2. 3.

To add or subtract two matrices, they must have the same size. You can use the + or - operators to
perform element-wise addition or subtraction. For example, to add the matrices C and D, you can
type:

-->C = [ 7 ; 8 ; 9 ]

-->D = [ 10 11 ]

-->C + D

Operator +: Wrong dimensions for operation [3x1] + [1x2], same dimensions expected.

-->A = [1 2 3; 4 5 6]

-->B = [-1 1 5; 2 -3 4]

-->A+B

ans = [2x3 double]

0. 3. 8.

6. 2. 10.

-->A-B
ans =

2. 1. -2.

2. 8. 2.

To multiply two matrices, the number of columns of the first matrix must equal the number of rows
of the second matrix. You can use the * operator to perform matrix multiplication. For example, to
multiply the matrices A and B, you can type:

-->A = [1 2 3; 4 5 6]

-->B = [-1 1 5; 2 -3 4]

-->A*B

Operator *: Wrong dimensions for operation [2x3] * [2x3].

-->A = [1 2 3; 4 5 6]

-->B = [ -1; 0 ; 1 ]

-->A * B

ans = [2x1 double]

2.

2.

For this part, create a new scinotes file and type the following. Run and save the file. See the results
in the console.

// save this file as arithmetic_operation1

A = [2 -1 0; 3 1 2; 4 5 -1];

B = [1 2 3; 4 5 6; 7 8 9];

disp(A)

disp(B) // display the matrix

// perform and display the subtraction of the matrices

disp('The subtraction of A and B is:')

disp(A - B)

// perform and display the multiplication of the matrices

disp('The multiplication of A and B is:')


disp(A * B)

// from here, save and run your scinotes file for the results, then exit file for the results
shown on command console.

You can use the input function to accept the elements of a matrix from the user. The input function
takes a string as an argument and displays it as a prompt. You can also specify the type of the input
by using the 'string', 'double' or 'integer' keywords.

For example, to ask the user for a 3x3 matrix, you can use the following code:

// This is a new scinotes file and save this file as arithmetic_operation2

A = [] // initialize an empty matrix

// Loop through each element and prompt the user to input values

disp("Enter the elements of the matrix:");

for i = 1:m

for j = 1:n

A(i, j) = input("Enter element (" + string(i) + "," + string(j) + "): ");

end

end

disp(A) // display the matrix

// Your scinotes file for arithmetic_operation2 ends here.

You can repeat the same process for another matrix, say B, and then display the result of any
operation you want.

For example, to display the result of A + B, you can type:

disp(A + B) // display the sum of the matrices

// Open the previous file arithmetic_operations2

// Save the file as arithmetic_operations3

// Add the following program at the end of the existing program, and when done, run and
save the file.
// create a matrix B with the same dimensions as A

B = zeros(3,3) // initialize a 3x3 matrix of zeros

// Loop through each element and prompt the user to input values

disp("Enter the elements of the matrix:");

for i = 1:m

for j = 1:n

B(i, j) = input("Enter element (" + string(i) + "," + string(j) + "): ");

end

end

disp(B) // display the matrix

// perform and display the addition of the matrices

disp(A + B) // display the sum of the matrices

// perform and display the subtraction of the matrices

disp('The subtraction of A and B is:')

disp(A - B)

// perform and display the multiplication of the matrices

disp('The multiplication of A and B is:')

disp(A * B)

This laboratory activity ends here. Perform the following lab exercises using the lecture on
SCILAB above. You may use SCILAB Notes or use the command console for the execution of this
exercises.

If you choose to place it in SCINOTES, you may combine the exercises from numbers 1-5, ‘a’
to ‘j’ into a single file and save it as lab_exercises2. Go to command console and copy and save the
output of this lab_exercises2 in a document file, and label it as lab_exercises2_output.

If you choose to do the activity in the command console, go to command console and copy
and save all the commands and output of this lab exercises in a document file, and label it as
lab_exercises2_output.

Lab Exercises

1. Identify the number of rows and columns in each matrix:


(a) A=[1 2 3;4 5 6]
(b) B = [ -1 0 1 ]
(c) C=[7;8;9]
(d) D = [ 10 11 ].
(e) E = [ 2 4 5; 1 -3 2 ; 4 7 -3]
(f) F = [ -2 3 6 ; 0 2 4]
(g) G = [ 4 0 1; 2 1 -2 ; 1 1 2]
(h) H = [ -1 ; 3 ; 4 ]
(i) I = [ 0 -2 13 ; 1 2 -4 ]
(j) J = [ -1 -2 1 ; 2 -1 3 ]

2. Determine the size of the given matrices.


(a) A = [ 1 2 3 ; 4 5 6 ]
(b) B = [ -1 0 1 ]
(c) C = [ 7 ; 8 ; 9 ]
(d) D = [ 10 11 ].
(e) E = [ 2 4 5; 1 -3 2 ; 4 7 -3]
(f) F = [ -2 3 6 ; 0 2 4]
(g) G = [ 4 0 1; 2 1 -2 ; 1 1 2]
(h) H = [ -1 ; 3 ; 4 ]
(i) I = [ 0 -2 13 ; 1 2 -4 ]
(j) J = [ -1 -2 1 ; 2 -1 3 ]

3. Add the following matrices if possible:


(a) A + B
(b) A + C
(c) B + D
(d) C + D
(e) A + I
(f) I + J
(g) A + F
(h) E + G
(i) C + H
(j) B + H
4. Subtract the following matrices if possible:
(a) A + B
(b) A + C
(c) B + D
(d) C + D
(e) A + I
(f) I + J
(g) A + F
(h) E + G
(i) C + H
(j) B + H

5. Multiply the following matrices if possible:


(a) AB
(b) AC
(c) BA
(d) CA
(e) BC
(f) CB
(g) CD
(h) DC
(i) GE
(j) IC
Lecture on Matrix Operations:

Minors, Cofactors, Adjoint, Transpose, Determinants, Rank, and Inverse

Introduction to Matrix Operations

Matrix operations are fundamental concepts in linear algebra with wide applications in engineering,
physics, computer science, economics, and more. In this lecture, we will explore key matrix
operations and concepts such as minors, cofactors, adjoints, transpose, determinants, rank, and
inverse of a matrix.

Minors of a Matrix

Definition:

The minor of an element in a matrix is the determinant of the submatrix formed by deleting the row
and column of that element.

Example:

Consider a 3x3 matrix:

The minor of element a11(which is 2) is obtained by deleting the first row and first column:

The minor of element a12(which is 3) is obtained by deleting the first row and second column

The minor of element a21(which is 4) is obtained by deleting the second row and first column

Cofactors of a Matrix

Definition:

The cofactor of an element aij is given by:


It accounts for the sign change depending on the position of the element.

Example:

For the element a11 = 2 in the matrix A above:

For the element a12 = 3 in the matrix A above:

For the element a21 = 3 in the matrix A above:

Transpose of a Matrix

Definition:

The transpose of a matrix is obtained by swapping its rows and columns.

Example:

For matrix A:

Its transpose is:

Adjoint of a Matrix

Definition:
The adjoint (or adjugate) of a matrix is the transpose of the cofactor matrix.

Steps:

1. Compute the cofactor of the given matrix.

2. Transpose the cofactor matrix to obtain the adjoint.

Example:

Given the cofactor matrix of B:

The adjoint is:

Determinants of a Matrix using Cofactor Method

Definition:

The determinant of a matrix is a scalar value that provides important properties about the matrix,
such as whether it is invertible.

Steps:

1. Choose any row or column.

2. Multiply each element by its cofactor.

3. Sum the results to get the determinant.

Example:

For matrix A:
Determinants of a Matrix using Gaussian Elimination Method

Definition:

This method reduces the matrix to upper triangular form using row operations, and the determinant
is the product of the diagonal elements.

Steps:

1. Perform row operations to obtain an upper triangular matrix.

2. Calculate the determinant by multiplying the diagonal elements.

Example:

For matrix A:

1. Perform row operations to get:

2. Determinant

Rank of a Matrix

Definition:

The rank of a matrix is the maximum number of linearly independent rows or columns.

Steps:

1. Use row reduction (Gaussian elimination) to bring the matrix to row echelon form.

2. Count the number of non-zero rows.

Example:

For matrix C:

1. After row reduction:

2. The rank of matrix C is 2 (since there are 2 non-zero rows).


Inverse of a Matrix

Definition:

The inverse of a matrix A is a matrix A-1 such that A*A-1 = I, where I is the identity matrix.

Steps:

1. Compute the determinant of A.

2. If the determinant is non-zero, calculate the inverse using:

Example:

For matrix A with det(A) = and adjoint of A =


Laboratory Exercise: Matrix Operations Using Scilab

Objective:

This lab exercise will guide you through performing matrix operations in Scilab, focusing on
calculating minors, cofactors, adjoint, transpose, determinants, rank, and inverse of matrices. By
the end of the exercise, you should be able to implement these operations using Scilab.

Required Software:

Scilab (Ensure Scilab is installed on your system)

Part 1: Setting Up the Environment

1. Open Scilab:

Launch Scilab on your system.

2. Create a New Script:

In the Scilab console, go to `File > New > Script` to open the script editor.

Part 2: Matrix Definition

Start by defining a matrix `A` in Scilab:

Part 3: Minors of a Matrix

Task:

Write a function to compute the minor of a given element in a matrix.


Part 4: Cofactors of a Matrix

Task:

Compute the cofactor of an element using the minor function.

Part 5: Adjoint of a Matrix

Task:

Calculate the adjoint of a matrix using cofactors.


Part 6: Transpose of a Matrix

Task:

Compute the transpose of matrix `A` directly.

Part 7: Determinant of a Matrix using Cofactor Method

Task:

Calculate the determinant using the cofactor method.


Part 8: Determinant of a Matrix using Pivotal Method

Task:

Calculate the determinant using Gaussian elimination (Scilab built-in function).

Part 9: Rank of a Matrix

Task:

Calculate the rank of matrix `A`.


Part 10: Inverse of a Matrix

Task:

Compute the inverse of matrix `A`, if it exists.

Part 11: Final Task - Complete Example

Task:

Given a 3x3 matrix `B`, perform all the operations learned above.
Part 12: Submission

1. Run your script: Ensure your script runs without errors.

2. Save your script: Save the script as `matrix_operations.sce`.

3. Submit: Upload your `.sce` file and results to the course submission portal.
Conclusion:

This lab exercise provided hands-on experience with matrix operations in Scilab. You explored how
to calculate minors, cofactors, adjoint, transpose, determinants, rank, and the inverse of matrices.
Practicing these operations will deepen your understanding of matrix algebra and its applications.
Solutions of Simultaneous Linear Equations

1. Elimination Method:

This is a process of eliminating one variable from a system of equations to solve for the other.
Here's the step-by-step process:

Example:

Solve the following system:

Step-by-Step Solution:

Step 1: Align both equations. Make the coefficients of one variable (e.g., \( x \)) the same in
both equations by multiplying equation (1) by 2:

Equation (2) remains unchanged:

Step 2: Subtract equation (2) from equation (3):

Solve for (y):

Step 3: Substitute into one of the original equations, say equation (1):

Thus, the solution is and .

2. Cramer's Rule:

Cramer's Rule applies to systems of linear equations where the number of equations matches the
number of unknowns. It uses determinants to find the solution.
Example:

Solve the following system using Cramer's Rule:

Step-by-Step Solution:

Step 1: Write the system in matrix form:

Step 2: Find the determinant of the coefficient matrix:

Step 3: Find by replacing the first column of the coefficient matrix with the
constant column:

Step 4: Find by replacing the second column of the coefficient matrix with the
constant column:

Step 5: Solve for x and y:

Thus, the solution is and .

3. Gaussian Elimination:

This method transforms the system into an upper triangular matrix, making it easier to solve the
system through back substitution.
Example:

Solve the system:

Step-by-Step Solution:

Step 1: Write the augmented matrix:

Step 2: Use row operations to create an upper triangular matrix. We can eliminate
from the second equation by performing .

Step 3: Solve for using the second row:

Step 4: Substitute into the first row:

Thus, the solution is and .

Simultaneous Linear Equations with Three Unknowns

System of Equations:

1. Elimination Method

The goal of the elimination method is to eliminate one variable at a time, reducing the system of
three equations to two, and eventually to one.

Step-by-Step Solution:
1. Start with the system:

2. Eliminate between the first and second equations:

Subtract equation (1) from equation (2):

3. Eliminate between the first and third equations:

Subtract equation (1) from equation (3):

Now, you have two new equations in terms of y and x:

4. Solve equation (5) for :

5. Substitute into equation (4):

6. Substitute the expressions for x and y into equation (1):

Simplifying:
7. Substitute into the expressions for x and y:

Thus, the solution is:

2. Cramer's Rule

The system of equations can be written in matrix form as:

Step-by-Step Solution:

1. Find the determinant of the coefficient matrix (D):

Expand this determinant:


2. Find by replacing the first column of the coefficient matrix with the constants on the
right-hand side:

Expand the determinant:

3. Find by replacing the second column of the coefficient matrix with the constants on
the right-hand side:

Expand the determinant:

4. Find by replacing the third column of the coefficient matrix with the constants on the
right-hand side:

Expand the determinant:


5. Find the solution:

3. Gaussian Elimination

We apply Gaussian elimination to convert the system into upper triangular form and then use back
substitution.

Step-by-Step Solution:

1. Write the augmented matrix:

2. Eliminate the -terms from the second and third rows:

Row 2:

Row 3:

3. Eliminate the -term from the third row:

Row 3:
4. Back substitution:

From the third row:

From the second row:

From the first row:

Thus, the solution is:

Summary:

Elimination Method eliminates variables by manipulating equations directly.

Cramer's Rule uses determinants for solving systems of linear equations.

Gaussian Elimination uses row operations to reduce the system to an upper triangular
matrix for back substitution.

The **Gauss-Jordan elimination method** is an extension of the Gaussian elimination method,


where the system of linear equations is transformed into **reduced row echelon form (RREF)**.
This form directly provides the solutions to the system. The main difference from Gaussian
elimination is that you eliminate not just below the pivot, but above it as well, to make the system a
diagonal matrix.

Gauss-Jordan Elimination for Two Unknowns

Example:

Solve the following system of equations using Gauss-Jordan elimination:

Step-by-Step Solution:
Step 1: Write the augmented matrix:

Step 2: Use row operations to reduce the matrix to echelon form (RREF). We can
eliminate from the second equation by performing:

Then, set the diagonal in R2 equal to 1.

Step 3. Eliminate in the first row:

Then, set the diagonal in R1 equal to 1.

Now, the system is in reduced row echelon form (RREF), and the solution is:

Gauss-Jordan Elimination for Three Unknowns

Example:

Solve the following system of equations using Gauss-Jordan elimination:

System of Equations:
Step-by-Step Solution:

1. Write the augmented matrix:

2. Use row operations to reduce the matrix to echelon form (RREF). Eliminate the -
terms from the second and third rows:

Row 2:

Row 3:

3. Eliminate the -term from the third row:

Row 3:

4. Reduce the diagonal of R3 to 1.

5. Use row operations to reduce the matrix to echelon form (RREF). Eliminate the -
terms from the first and second rows:
6. Reduce the diagonal of R2 to 1.

7. Eliminate the -term from the first row:

8. Reduce the diagonal in R1 to 1.

Now that the solution is in reduced row echelon form, the solution is:
Laboratory Exercise: Simultaneous Linear Equations Using Scilab

Objective:

This lab exercise will guide you through performing solutions of simultaneous linear equations in
Scilab, focusing on elimination method, Cramer’s Rule, Gaussian Elimination and Gauss-Jordan
Elimination Method. By the end of the exercise, you should be able to implement these operations
using Scilab.

Required Software:

Scilab (Ensure Scilab is installed on your system)

Part 1: Setting Up the Environment

1. Open Scilab:

Launch Scilab on your system.

2. Create a New Script:

In the Scilab console, go to `File > New > Script` to open the script editor.

Part 2: Elimination Method

In the elimination method, we manually eliminate variables by combining equations to reduce the
number of unknowns.

System of Equations:
NOTE: Save file as ‘eliminationmethod’

Part 3: Cramer’s Rule

Cramer's Rule solves the system by computing determinants. We manually compute the
determinants of the matrices.

System of Equations:
NOTE: Save file as ‘cramersrule’

Part 4: Gaussian Elimination Method

Gaussian elimination involves converting the matrix into upper triangular form and then back
substitution.

System of Equations:
NOTE: Save file as ‘gaussianelimination’

Part 5: Gauss-Jordan Elimination Method

Gauss-Jordan elimination involves converting the matrix into reduced row-echelon form (RREF).

System of Equations:
NOTE: Save file as ‘gaussjordan’

Solve the following equations using the different methods above.

Problem 1.

Problem 2

You might also like