Friday, 12 August 2011

Matrices

Matrices is a square or rectangular array which can be used to store a wide variety of number. It has a wide applications in mathematics , engineering and physics too. It is first mentioned in mathematics literature paper by James Joseph Slyvester,  the word matrix itself meant "a place which something is bred, produced or developed".

How it is applied in real life ?
Although it may not seems to be apparent in our life but it is there, lets say, we had 2 friends named Mr Sci and Mr Lab, one of them is purely vegetarians and one of them is erm.. carnivore (who likes to eat meat with bit of homemade tomato ketchup). So Mr Sci bought 4 kg of tomatoes and absolutely no meat meanwhile Mr Lab bought 1 kg of tomato with 3 kg of meats. Hence, how you can draft in in matrices ? Below is one of the examples.  We first draft it into a table such as follows ...


Tomato Meat
Sci 4 0
Lab 1 3


and then draft it as followings


This whole things included brackets is known as matrix, but if you want to be more specifics, it is two by two matrices. 

So, in Scilab, you just need to do this ...

//Displaying matrices in Scilab

//If you need to add extra column, just add 
//semicolon ";" to separate between columns

//So if your matrix is like this

M = [4,0;3,1]

//It will shows 
// 4      0
// 3      1

That is all for today. :]

(P.S: I don't know what is happened with Blogger . Suddenly , I can't post snippets today!)


Tuesday, 9 August 2011

Knowing Scilab

I assume now you are experimenting a bit on the Scilab but if not, I will explain it to you the components that make the Scilab works anyway. Below is a screenshot of the Scilab console with some highlighting.


As you can see, it is pretty minimalistic with the red marking on top is the menu bar which makes Scilab works and the blue highlighted below is the workspace which where the Scilab source code can be directly run in here.
By the way, you should see something like above, if you see any error messages, it is wise to reinstall again or even re-download the whole Scilab install files (which are maybe corrupted in your hardisk).

Now, let us discover what of this each icons in red highlighting do...

This icons represents Open SciNotes pad where you can type the equations without fearing for typing mistake which will be encountered if it is entered in Scilab consoles.

This icons represents Open File which let user opens up their already created Scilab files which are in sci or sce format.

This icon represents the Cut,Copy and Paste functions which probably you are familiar with. 

This icon represents change directory icons and although it may seems like it is open file icon but never ever change the default directory settings.

This icon represents changing the font used in the Scilab console

This icon functions to print out your source code on paper

This icons is to let you manage (install/update/uninstall) the external toolbox modules which are not available in the Scilab core files

This icon is Xcos which lets you design a system/model using the block diagram (but as of version 5.3.2, there are some bugs which are not yet fixed)

This is Scilab demo icon which you can run a few Scilab examples  (but again there are few bugs with some of the examples, especially some of the Xcos examples)

 and of course the help files ! :P

That is all for now ...

















Saturday, 30 July 2011

Recap: First Scilab Addition

Ok, so you may have played around with the addition and every other type of symbol but if you haven't got the rest of operation symbol, below is the included symbols for any operation that you might not known.


OperationSymbol
Addition+
Subtraction-
Multiplication*
Division/

Let us see back the addition code again, shall we ?



Now we look at the first and second line.
They both started with // which means anything that are typed after the // are ignored by the Scilab because // meant it is the comments.

It may seems a trivial matter to put comments but if the program that you made are very long, you need to know what it does for certain parts in the program so that you know what that parts do when you came back to it later on. For those in programming background, so ... yah it is like C/C++ commenting system.


Then we moved on to third and fourth line,
a = 6.80
b = 14.90

Here we are going to explain the concepts of variable. A variable is a placeholder (element) where the value is liable to be changed. The third and fourth lines above shows variable assignment where the variables receive the initial values. The format are as follows

[variable name] = [expression]

We are going to use a box and ball analogies to explain variables.  
Assuming we had 3 variables (box) a, b and c. 
We are going to put some balls into box a and box b.





To provide more clear illustrations, we are eliminating the decimal points and round up the number to nearest integer. (Or else, how do you define 3.75 balls ?)

First we put 15 balls in box a and 9 balls into box b.

Hence, box a and box b is operand, which meant that it consists a value that a operator ( +  -  /  * ) can work on. In Scilab, we are assigning a value in the variable a and variable b. Note that the variable is on the left side meanwhile the values in right hand side.

Later, both contents in box a and box b is summed it together inside box c.
We look at line 6:  c = a+b
The line 6 shows arithmetic expressions where the two of operand are executed with the the operations. The format for followings are as follow for most cases:

[variable] = [variable] [result] [variable]


Therefore box c is the variable results where whatever operations has done is shown here.So in the end, we get a total of 26 balls !

Hence, we calculate the total number of balls inside box c and also in Scilab, we can get the sum of additions after addition operation is completed.

Plus, if you are coming from a programming background and you might accidentally put a semicolon ( ; ) at the end of each line. No worries, it won't affect your operation flow, it will just hide the display in the Scilab console. There are no official key-name for semi colon in Scilab but since it suppressed the result displayed, we are going to named it as suppressor.  Below is an example by what we meant. . .



As you run it, you will not see the results for c = a+b ; but you will see the results for d = 50 - c .
It is very useful for looping where we will not want to see the repeated results being displayed and we just want to see the final result being published.

That is all for today !


Friday, 29 July 2011

First Scilab Addition

Okay, now before starting the basics of Scilab learning, there are few assumptions that I am going to make:

1. You know how to use g00gle.com to search for Scilab installer and download it.
2. You had some elementary logical thinking

Okay, back to the topics, you still remember the market analogies for algorithms discussed last time ?
Here is the code for Scilab.



You can download it (click on "raw") and run it through the Scilab, but if you are the hardworking type and type the code for yourself, then here is how you code it.


You should be able see something loaded like this.  Select Applications tab on menu bar and click on SciNotes.


Again you should see the following Scinotes consoles popping out.


Now, you can start typing your code straight away !

Press "Ctrl+A" to select all the text and "Ctrl+E" to execute the code in the Scilab .
Supposedly, you can see the answeras 21.7 which is same as the algorithms discussed in last blog post.

Now you may try to do the execution operation for subtraction, multiplication and division and you can mathematically program for yourself and see if it is really working as it should be. 
In next blog post, I am going to show you how it is works.

Sunday, 24 July 2011

Simple concepts before starting . . .


Before we even made the first step into programming in Scilab, there are some concepts that we must understand first ...


First is algorithm or their short form, algo . 

What is it actually ?

To describe it in pure mathematical form [with the theorem and equations] is somewhat difficult (at least for me), but let me give an examples for a clear illustrations (perhaps maybe in a too simple but maybe a bit long winded analogies).

Say ... you go shopping (with environmental friendly bag) in a big giant hypermarket.

And you see tomato priced at $6.80 per kg and also meat priced at $14.90 per kg.
So you decided to buy 1kg of tomato and 1kg of meat

So now is where the algorithm part coming. Then, you would want to know how much it costs for 1kg of tomato and 1 kg of meat.

We need the addition operations to sum up the total price of both groceries that we buy.

It maybe hard to compute in head (maybe you are maths king) but let us compute in the a piece of used paper.

Following describes the additions operations for tomato and meat step by step in algorithms.

Step 1:
Write down and align both numbers in columns from the right.Make sure that price listed is only up to 2 decimal points.
 Step 2:
Starting from rightmost columns, work out the additions to the left columns by columns through various columns


Step 3:
Compute summations and write down the summations of the digits of same columns. If the addition produces overflow (summation more than 10) , carry the overflow to its next left columns Make a small mark number 1 to denote any overflow from its right columns.

Step 4:
If there are no columns to the left, stop.
Otherwise, move to next columns to left and repeat Step 3.

So, the total of the groceries that you computed in paper is amount to $21.70.
(Side joke: Thanks to certain governing entity failing to curb out the rising inflation of foodstuffs)

So you had $50 inside the purse/wallet. So, you handed over the $50 to the grocers and you expect that there are balances.

Now, let assumes that you are a grocers and you need to compute what amount of balances that you should  give back to the customer.
Same as above, we need algorithms again but now we need minus operations to find out the balances to give back to customer.

Again, we discuss algorithm but this time it is minus operation for $50 and $21.70.

Step 1:
First, we write down the two number but the larger number is above the smaller number and both are aligned from the rightmost columns.

Step 2:
Starting from rightmost columns, work out the subtractions to the left columns by columns through various columns





Step 3:
Compute summations and write down the summations of the digits of same columns. If subtraction produces negative digit, borrow 1 from top number to the left. The current columns which is worked on are given "10" for it to be subtracted.


Step 4:
If there are no columns to the left, stop.
Otherwise, move to next columns to left and repeat Step 3.

So the grocers should give balances of $28.30 back to customer.
 
As you seen from 2 examples above, we can see how the algorithms are working. Besides used extensively in numerical computations, algorithms can be seen as recipe (not necessary restricted to cooking only) which contains of instructions which acts as solutions for the problems given. 



Below I summarized the characteristic of the algorithms . . .

(1) Algorithms have consisted a finite number of instructions. (4 steps in both addition and subtraction)
(2) The individual instructions should be very well defined for the computing agents ( in this case : customer and grocers) to be able to execute or perform execution effectively.
(3) Algorithms solves a general class of problems (General in case of subtractions where it is applicable for the balances should be greater than $0.00)
(4) Algorithms will halt after the solutions is found (See the Step 4 in both of the examples)

Okay, that's all. If you found anything missing or anything wrong, just left it in comments below. ^_^

Wednesday, 20 July 2011

Hello World !

Hi, world. I am just graduated engineering students currently working in a MNC in Silicone Island of East as an engineer ! ^_^

I am very interested in Scilab when I am into the final year when my university is converting the usage of Matlab into Scilab after the license term expired.


So, what we learn in Matlab is maybe gone wasted but the Scilab usage is gaining popularity (at least in my uni) due to its being free, modular (many free selections of toolboxes available over Internet) and also it is being constantly updated by Scilab Consortium.



But mind you, I am starting this blog to share anything that I learn in Scilab. I am not a pro-Scilab user as of yet. But if you encounter any problems / got more ideas to share, please email me or leave a comment in post below.  

To sign off, I presents you with a Scilab Code:

:) This maybe look a bit like C programming language but I assure you that it is going to be working correctly in Scilab 5-3.2 at least.
 



If you had installed Scilab 5-3.2, try copy and paste it.
(Not forgetting to mention, run it !)