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 !


No comments:

Post a Comment