التسميات

الثلاثاء، 31 يوليو 2012

Some remarkable difference between matrix and list in Scilab

When comparing Scilab with C++, we will find that matrices in Scilab are equivalent to arrays in C++ and lists in Scilab are equivalent to structures in C++. Lists (data structures) are preferable when creating a database or when a set of data has no specified layout. The following points are some differences between matrices and lists in Scilab:
§  Matrix elements must be all of the same type (.i.e. matrix of strings, sparse matrix, polynomial matrix, real matrix, ... ) , while the list can store different types of elements like numbers, strings, matrices, sparse matrices, polynomial, functions, ... and for this reason lists (typed lists) are implemented in graphic window properties, axes properties, entity properties, and ... etc. in Scilab as it contains mixed types of data, like the following:

Figure property
Type
Type No.
Children Matrix of graphic handles 9
Figure position Real row vector of size  1 x 2 1
Figure size Real row vector of size  1 x 2 1
Axes size Real row vector of size  1 x 2 1
Auto resize Matrix of character strings 10
View port Real row vector of size  1 x 2 1
Figure name Matrix of character strings 10
Figure ID Real matrix 1
Info message Matrix of character strings 10
Color map Matrix of size M x 3, where M is number of colors and 3 is the RGB channels 1
Pixel map Matrix of character strings 10
Pixel drawing mode Matrix of character strings 10
.
.
.
.
.
.
.
.
.

For example, you can use lists to create a data base for employees and this data base contains the following data:
□     Employee name (string)
□     Employee age (real matrix)
□     Employee salary (real matrix)
□     Employee is married or not (Boolean)
□     Employee notes (empty in case there are no notes)


§  Number of elements in each row in a matrix is the same, while in lists each row (entry) can has different number of elements

§  Matrix can't store an empty row while list can do

السبت، 28 يوليو 2012

Where to find magnets in our daily life

In fact this post should not be a post since it is not that important, but it will. In some developing countries like my lovely country (Egypt) there are no sellers or manufacturer for magnets or there are some but difficult to find or reach. Many times I needed magnets to do some experiments or models, but I didn't find someone who sells magnets. Therefore, I decided to use magnets found in some available products around us. The following list is some of the products that you may extract magnets from them if they are scrapped:



§  Speakers of computer, telephone, cell phone, TV boxex, and headphones

§  Fridge door seal

§  Cabinet magnetic catch (bathroom cabinet, kitchen cabinet, closet, ...)

§  Magnetic door catch (wall-mounted)

§  Magnetic door catch (ceil-mounted)

§  Door magnetic switch/sensor (used to switch on bells or lights when door is opened)

§  Small toys' DC motors (flexible/rubber magnet)

§  DC motors

§  Hard disk (Neodymium magnet)

§  Laptop standby locking switch (not all laptops)

§  Fridge magnets used to stick papers of "notes" or "to do list" on fridges

§  Soap magnetic holder

§  Magnetic-base antenna mounted on cars

§  Small chess with magnetic base

§  Magnetic singing eggs: are one of the most popular toys in the world. Made from highly polished hematite magnet material, they have a deep black color and ultra smooth finish. Normally they are elliptical and sphere shape.
These eggs are incredibly fascinating. Whenever they are separated, they will try to find each other. When they do, amazing thing happen. If you throw them to the sky, they will give out nice snake sound caused by strong magnetic attraction. So "snake eggs" is another cute nickname. It is also a healthy massage. When you feel tied, their magnetism will do good to your body.
§ Desk magnets used for collecting paper clips

§ Fishing toy

§ Magnetic white board eraser, and white board magnets

§ Magnetic pin holder used by tailors

§ Magnetic picture frames

If you have some suggestions on where to find magnets in products all around us, leave a comment.

الخميس، 26 يوليو 2012

Copying from microsoft office word to blogspot post editor

Writing your posts in Microsoft office word and copying and pasting them back in your post in blogspot is a great deal since the GUI of the post editor in blogspot lacks to some features that are already compatible with the site. The following are some examples of some items I copied from microsoft office 2010.
 
Superscripts      ⟾    BlogSpot
Subscripts     ⟾     BlogSpot
Underlining     ⟾     Single line with only one style  
Text highlighting with specific colors     ⟾    Highlighted text
Strike  through   ⟾     Stroked through text
Variety of font sizes ⟾ 30 28 26 24 22 20 18 16
Bullets with different styles
□     Line 1
□     Line 2
§  Line 3
Different fonts that does not appear in blogspot editor    BankGothic Lt BT    Algerian      Broadway
Table with different effects














Symbols     ⟾    © ® ∞ [ S

Edge flipping in Delaunay triangulation

Edge flipping is applied on internal edges (edge shared with two triangles) if they are illegal and can’t be applied on boundary edges. In triangulation (and meshing in general), all triangles (cells) should have the same notation direction (orientation) as this is useful in edge-based data structures used in rendering and simulation. The main trick in edge flipping is the notation of the new triangles. That means: if the original triangles are written in clockwise/counter clockwise orientation (order), then the new triangles should have the same orientation.

Consider that we have two adjacent triangles like the following (written in Scilab/Matlab syntax):

OldTri1=[A, C, B];     OldTri2=[D, B, C];

Where A, B, C, D are integers representing the indices of the vertices, and in our case the notation orientation is clockwise.

Steps of flipping:

§  Get the vertices of the shared edge ⟾ the shared edge is [B, C] or [C, B]

§  Get the edges of the first triangle ⟾ edges=[A, C;C, B;B, A]

§  Remove the shared edge from the edges of the first triangle ⟾ edges=[A, C;B, A]

§  We have two triangles with total of four vertices. Now, get the vertex that we can call far vertex. This vertex is simply the fourth vertex that does not belong to the first triangle, in our case the far vertex is D

§  Now, the new triangles after flipping are

NewTri1=[(the first edge/row in edges) (far vertex)]=[A, C, D];
NewTri2=[(the second edge/row in edges) (far vertex)]=[B, A, D];



الاثنين، 23 يوليو 2012

"Set theory" operations in Scilab: union, intersection, and difference

In Scilab, there are 4 commands for "set theory":

1. Union operation of two data sets
2. Intersection of two data sets
3. Difference of two data sets
4. Unique elements of data set



Union operation is used in Scilab as the following (as Matlab)



The intersection of two data sets is computed like the following


The difference between two data sets  is computed like the following. You should remeber that difference is not commutative.


Finally, the unique command is used to get the unique elements of a data set with no repetition.

A thing to consider that all the results of set operations are row vectors. The inputs of set operations in Scilab can be matrices or vectors and they are automatically and internally converted to vectors to deal with.

السبت، 21 يوليو 2012

Function definition in Scilab

So ..., quickly, let's remember what is a function ? A function is a set of commands and operations that are applied to inputs to give us certain outputs. A function is preferred in situations where a block of code is usually used and this -of course- saves programmer's (Scilaber's) time and effort and makes the code compact and small. Another power of functions in Scilab that all the internal variables used in any function are killed (erased) after executing the function.

The following method is used in defining a function



There are many things to note:

Outputs (output variables) should be written in one of the following formats according to the number of outputs


Also, inputs should be written in one of the following formats according to the number of inputs


الأربعاء، 18 يوليو 2012

using Scilab code in TCL-TK (tutorial)

The key to use Scilab code in TCL-TK interpreter is a command called ScilabEval. As the name implies, the command is responsible for evaluation of Scilab commands (syntax) inside TCL-TK. The following hints are to be considered when using this command:

1. Syntax

The command should be used in this manner


You can use this command many times in a single line like the following


2. Common mistakes

The Scilab code should start and end with double quotation mark (") not single quotation mark ('), otherwise an error will be returned by Scilab console.


 Also, the Scilab code should all be placed in one line not in multi lines, otherwise the first line only will be executed.



If you want to use strings in the Scilab code use single quotes (') instead of double quotes in order to prevent Scilab from confusing or misunderstanding of start and end quotes.


A simple explanation of this problem is that Scilab detects only the first and second occurrences of the double quotes and executes what is between them.



I think these are the common mistakes and problems that may make you pull out your hair if you don't know them.


Scilab and TCL-TK

TCL-Tk, TCL is an abbreviation for Tool Command Language and TK is an abbreviation for toolkit. In Matlab, graphical user interfaces GUIs are based on Java language (as I remember), while in Scilab, TCL-TK which is a powerful scripting language is used in Scilab. I admit that TCL-TK in Scilab is not well-documented, and this come from the fact that TCL-TK already has a wealthy documentation in its community site http://www.tcl.tk/ with a lot of examples and sample scripts. Another thing to know that Scilab has no GUI or toolbox to create GUIs using TCL-TK (like Matlab).

From my point of view, TCL-TK is a great scripting language and may be the easiest one to use for creating GUIs, it includes all types of GUI elements (widgets) like buttons, radio buttons, check boxes, scroll bars, scales, canvas (for drawing), labels, entries, combo boxes, and a lot more. It also supports string and math operations and functions. The following capture is just to show the power of TCL-TK GUI (I created this simple GUI using my GUI builder project which is not suitable for proffesional use. By a little help of you we can improve this project).




So, what's new with Scilab ? . The greate thing in Scilab that you can create GUIs in Scilab environment using TCL-TK and exchange data and variables between Scilab and TCL-TK so that you can make Scilab make calculations and plots by clicking a button or scrolling a scale and so on.

The aim of this post is not to show how to use TCL-TK in Scilab, but is to show you that there is a buried treasure inside Scilab. Really, Scilab is very precious.

The idea beyond fiber construction


There are many applications in our lives that use the fiber construction of materials like clothes, nylon ropes, steel ropes, fiber-glass, etc. In this post I’m going to consider the idea beyond using fiber construction in mechanical applications. Consider the figure below which represents two samples of the same material: one with continuous layout and the other is fiber-constructed and admire it.



Assume that those two samples are going to carry the same load with the same safety factor in the shown direction (direction is parallel to fibers in this case). Also, consider the presence of a crack (which may take place in our practical life) to the right of both samples. If the load is still applied on both samples, the crack will propagate till it reaches the other end of the sample as shown (end of crack propagation). On the other hand, the crack in the fiber-constructed material will terminates at the end of the fiber and the remainder of the fibers can carry the load, but with lower margin of safety.

So, and for this reason, the fiber construction is more preferable for being used in high safety applications like airplane (body is made of aluminum-carbon fibers), hoisting systems (cranes, lifts, …), three-bladed conventional wind turbines, and all other applications.