0% found this document useful (0 votes)
328 views

Matrix Operations Using Scilab

This tutorial provides an overview of matrix operations in Scilab. It introduces how to define vectors and matrices, perform basic operations like addition and multiplication, address elements, find transpose, and solve systems of equations. It also demonstrates how to create identity, zero, and random matrices. Key commands covered include size, eye, zeros, ones, rand, inv, and spec. The tutorial concludes by describing additional Scilab resources and spoken tutorials available in Indian languages.

Uploaded by

Arun kumar.N
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)
328 views

Matrix Operations Using Scilab

This tutorial provides an overview of matrix operations in Scilab. It introduces how to define vectors and matrices, perform basic operations like addition and multiplication, address elements, find transpose, and solve systems of equations. It also demonstrates how to create identity, zero, and random matrices. Key commands covered include size, eye, zeros, ones, rand, inv, and spec. The tutorial concludes by describing additional Scilab resources and spoken tutorials available in Indian languages.

Uploaded by

Arun kumar.N
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/ 10

Welcome to this spoken tutorial on Matrix Operations using Scilab.

To practice this tutorial, you need to have Scilab installed on your system. Open the scilab console window. Let us start by de ining a vector. This can be done in two ways! irst one is using spaces ""#p $ %& ' () p $ &. '. (.

or using commas. ""#* $ %', (, +) * $ '. (. +.

We can ind the length o a vector as ollows! ""#length,pans $ (. We can work with vectors, .ust as we do in Maths classes. We can add them! ""#p / * ans $ (. 0. 1.

We can subtract ""#* " p ans $ &. &. &.

and so on. Transpose o a vector can be ound using apostrophe. ""#p2 ans $ &.

'. (. This is also known as a prime or a single *uote. On my keyboard, it is next to the enter or return key. We can calculate p"transpose ,times-3 *! ""#p23* ans $ '. +. 4. 4. 6. (. 5. &'. +.

The command p times *"transpose gives a scalar! ""#p3*2 ans $ '7. 8 suggest that you pause at this point and check these calculations. 8 would want you to do this at regular intervals. When de ining matrices, the semicolon is used or de ining the next row. 9or example, de ine a ' by ( matrix : by typing ""#: $ %& ' (;+ 0 4) : $ &. +. '. 0. (. 4.

<ote that this : is in upper case. 8n Scilab, upper case variables are di erent rom lower case variables. Would you want to check what small p has at this point= The si>e o a matrix can be obtained by using the si>e command ""#si>e,:ans $ '. (.

answer is ' , ( We can assign these values to variables as ollows!

""#%row, col) $ si>e,:col $ (. row $ '. The transpose command works or matrices as well! ""#:2 ans $ &. '. (. +. 0. 4.

as given here Let us de ine another ' by ( matrix ?! ""#? $ %& 0 (;' + 5) ? $ &. '. 0. +. (. 5.

Let us also recall : once more! We can carry out calculations involving : and ?, .ust as we do in mathematics. 9or example, let us calculate! ""#@ $ '3: / (3? @ $ 0. &+. &6. ''. &0. (4.

Aou may want to veri y whether these calculations are correct. We can address the elements o matrices easily. 9or example, i we want to access the ',' element, we give!

""#@,','ans $ '' 8t is easy to address rows and columns o matrices. 9or example, the irst row o ? is obtained using the ollowing command! ""#@ r $ @,&,!@r $ 0. &6. &0.

Aou see that we get the irst row. The semicolon operator says, take everything. Bere, it says that we have to take all columns, namely, three columns. Let us recall @. The second to third columns o @ are obtained using ""#@st $ @,!,',(8 made a mistake so ' to ( is given by this colon operator ""#@st $ @,!,'!(@st $ &6. ''. &0. (4.

Ok you can see that. Let recall what @ is. Aou can see that. The irst colon says take everything. ' to ( says take rom ' to ( onwards 8 have a *uestion or you. What will @,!,!- give= 8 will not give this command. 8 would want you to try this out. 8 would want you to explain why it happens. One o the important operations carried out on matrices is elementary row operations. 8n this, we have to make entries below a number to be >ero. This can be done easily in Scilab. Let us recall :.

Suppose that we want to make the ,',&- entry >ero by elementary row operation. That is, we would want to multiply the irst row by + and subtract it rom the second row! ""#:,',!- $ :,',!- " +3:,&,!: $ &. '. (.

7. " (. " 4. Would you want to pause and check out this calculation= This procedure can be extended to larger systems and to elementary column operations. We can easily append rows and columns to matrices. 9or example, i we want to append a row containing %0 0 "'), we do the ollowing! ""#T $ %:; ,go to the next row- %0 0 "')) ,this row is over this operation is overT $ &. '. (.

7. " (. " 4. 0. 0. " '.

The semicolon a ter : says that the numbers coming a ter should go to the next row. We use matrix notation while solving e*uations. Suppose that we want to solve this matrix e*uation! Cmath# xD& / 'xD' " xD( $ & CEmath# Cmath# "'xD& " 4xD' / +xD( $ "' CEmath# Cmath# "xD& " (xD' / (xD( $ & CEmath#

This can be written as ollows Fx $ b The solution is given as 8nverse F times b Lets veri y whether this is correct F is given as ""#F $ %& ' "&;"' "4 +;"& "( () F $ &. '. " &. +. (.

" '. " 4. " &. " (.

""#b $ %&;"';&) b $ &. " '. &. This is the same system we saw here Let get back here We can calculate x using ""#x $ inv,F-3b x $ " &. '. '. we get this result We can also solve it in scilab with F reverse slash b 8t is as i this F is taken rom this side over here so it comes to the le t o b and because F divides b you put a slash in this manner Let us do it in Scilab ""#x $ FGb

x $ " &. '. '. We get the same result The irst method involves two steps! calculation o inverse o F and then multiplication with b. FGb .ust tells Scilab to solve this system. This is done in one step. Fs a result, FGb is generally more e icient. We can veri y the correctness o the solution by back substitution, that is, by calculating Fx"b! ""#F3x"b ans $ 7. 7. 7. We see that the solution is indeed correct. 8t is possible that in some systems we may not get >ero exactly. Hut we will get a number close to >ero, say, o the order o &7IJ"&4K or something like that. 9or s*uare matrices, we can calculate the determinants! Let us recall F irst! Lets calculate the determinant o F ""#det,Fans $ " '. We can calculate the s*uare or cube o a s*uare matrix F by simply typing FI' or FI(. Bere we use the carat symbol. 8n my keyboard, it is obtained by shi t 4. One can calculate the eigenvalues o a s*uare matrix by the command spec, which is a short orm or spectrum! as i do here ""#spec,F-

ans $ " (.1++5'4& 7.(606(&6 &.(+556+' 8t is possible to calculate the eigenvectors also using the spec command. Aou can ind the syntax or this by giving this command ""#help spec 8 will not give this command, however. Lsing Scilab we can create special matrices! 9or example we can create a matrix o >eros with ( rows and + columns using this command ""#>eros,(,+ans $

7. 7. 7. 7. 7. 7. 7. 7. 7. 7. 7. 7. F matrix o all ones can be created with ones command as ollows ""#ones,',+ans $ &. &. &. &. &. &. &. &. 8t is easy to create identity matrices as well! ""#eye,+,+ans $ &. 7. 7. 7. 7. &. 7. 7. 7. 7. &. 7. 7. 7. 7. &.

This is a + by + identity matrix. We o ten need matrices consisting o pseudo random numbers. These can be generated by using the rand command as ollows ""#p$rand,',(p$ 7.'&&('+6 7.777''&& 7.440(5&& 7.1047+(6 7.((7('1& 7.4'5(6&5

See help rand or options regarding the distributions and seeds. This brings us to the end o spoken tutorial on Matrix Operations using Scilab. We also have several other spoken tutorial on Scilab at this time. These are listed here. Scilab @ ort in 8ndia is co"ordinated through this website. scilab.in There are some interesting pro.ects one o them is the Textbook pro.ect That codes worked out examples o standard textbooks using scilab The link pro.ect allows users to link known scilab documents and to rank them We also help organi>e Scilab Workshops We have two mailing lists one or announce and another one or discuss. We invite your participation in all our activities Lets get back to spoken tutorials The spoken part will be available in various 8ndian Languages as well. These are available at spoken"tutorial.org These tutorial orm a part o Level 7 training in Scilab. These tutorials are available absolutely ree o cost. We wish to cover many 9OSS systems through this route. We welcome your eedback on these. We also welcome your participation On writing the outline or the so tware.

To write the original scripts. To record the spoken tutorial. To translate the script into various 8ndian Languages. To dub the audio in 8ndian Languages using the script. To review and give your eedback on all o the above. We welcome you to conduct workshops using these spoken tutorials. We also invite you to conduct e icacy studies on Spoken tutorials. We are also looking or experts who can give technology support or audio, video, automatic translation, etc. We have unding or all these activities The Spoken Tutorials are part o the Talk to a Teacher pro.ect, supported by the <ational Mission on @ducation through 8MT abbreviated as <M@8MT given by MBNO government o 8ndia. More in ormation on the same is available at this website http!EEspoken"tutorial.orgE<M@8MT"8ntro. Thanks or .oining us. This is Pannan Moudgalya signing o . Qoodbye.

You might also like