0% found this document useful (0 votes)
47 views2 pages

W5 Lesson 3 - Converting To Parallel and Distributed Simulation - Lecture PDF

Matrix operations in Scilab include addition, subtraction, multiplication, transpose, inversion, and determinant. Examples show defining and manipulating matrices, such as transposing matrix a and storing it in b, adding a and b and storing the result in c, and inverting matrix f and storing the result in g. The document also demonstrates using built-in functions to generate commonly used matrices, such as zero matrices with zeros(), identity matrices with eye(), and diagonal matrices. Creating vectors from ranges is also illustrated, such as the vector [1, 2, 3, 4, 5] from the range 1:5.

Uploaded by

yassin20dhmi
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)
47 views2 pages

W5 Lesson 3 - Converting To Parallel and Distributed Simulation - Lecture PDF

Matrix operations in Scilab include addition, subtraction, multiplication, transpose, inversion, and determinant. Examples show defining and manipulating matrices, such as transposing matrix a and storing it in b, adding a and b and storing the result in c, and inverting matrix f and storing the result in g. The document also demonstrates using built-in functions to generate commonly used matrices, such as zero matrices with zeros(), identity matrices with eye(), and diagonal matrices. Creating vectors from ranges is also illustrated, such as the vector [1, 2, 3, 4, 5] from the range 1:5.

Uploaded by

yassin20dhmi
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/ 2

Lesson 3 – Matrix Operations

Matrix operations built-in into Scilab include addition, subtraction, multiplication,


transpose, inversion, determinant, trigonometric, logarithmic, exponential functions and many
others. Study the following examples:
-->a=[1 2 3; 4 5 6; 7 8 9]; Define a 3x3 matrix. Semicolons indicate end of a row
-->b=a'; Transpose a and store it in b. Apostrophe (') is the transpose
operator.
-->c=a+b Add a to b and store the result in c. a and b must be of the
same size. Otherwise, Scilab will report an error.
-->d=a-b Subtract b from a and store the result in d.
-->e=a*b Multiply a with b and store the result in e. a and b must be
compatible for matrix multiplication.
-->f=[3 1 2; 1 5 3; 2 3 6]; Define a 3x3 matrix with name f.
-->g=inv(f) Invert matrix f and store the result in g. f must be square
and positive definite. Scilab will display a warning if it is ill
conditioned.
-->f*g The answer must be an identity matrix
-->det(f) Determinant of f.
-->log(a) Matrix of log of each element of a.
-->a .* b Element by element multiplication.
-->a^2 Same as a*a.
-->a .^2 Element by element square.

There are some handy utility functions to generate commonly used matrices, such as zero
matrices, identity matrices, diagonal matrices, matrix containing randomly generated numbers
etc.

-->a=zeros(5,8) Creates a 5x8 matrix with all elements zero.


-->b=ones(4,6) Creates a 4x6 matrix with all elements 1
-->c=eye(3,3) Creates a 3x3 identity matrix
-->d=eye(3,3)*10 Creates a 3x3 diagonal matrix, with diagonal elements equal to 10.

It is possible to generate a range of numbers to form a vector. Study the following


commands:

-->a=[1:5] Creates a vector with 5 elements as follows [1, 2, 3, 4, 5]


-->b=[0:0.5:5] Creates a vector with 11 elements as follows [0, 0.5, 1.0,
1.5, ... 4.5, 5.0]

A range requires a start value, an increment and an end value, separated by colons (:). If
only two values are given (separated by only one colon), they are taken to be the start and end
values and the increment is assumed to be 1 (a:b is the short form for a:1:b, where a and b
are numbers). The increment must be negative when the start value is greater than the end value.
You can create an empty matrix with the command:
-->a=[ ]

You might also like