tag:blogger.com,1999:blog-91017017131385387312024-03-05T12:43:48.090-03:00How to Use ScilabScilab is a software of scientific simulation.
It can operate with vectors, matrices, images, state space, and other kinds of situations.
I've been working with Scilab since 2005, and I always have success in my projects using Scilab.Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.comBlogger78125tag:blogger.com,1999:blog-9101701713138538731.post-27079634124165099772014-12-24T12:05:00.001-03:002014-12-24T12:05:48.481-03:00Keyboard input in running time<div dir="ltr" style="text-align: left;" trbidi="on">
MERRY CHRISTMAS!<br />
<br />
Dear readers, I hope you have a merry Christmas and a great new year!<br />
<br />
This is my last post in 2014, thus I'd like to say THANK YOU, for all my readers, this blog has been much visited and became a relevant reference for Scilab.<br />
<br />
This blog is the concretization of my will to share some knowledge about Scilab, and it's now a reference for people around the World.<br />
<br />
But, coming to the technical content, let's see something about using keyboard for input data in running time.<br />
<br />
Scilab has the function <b>input()</b>, that holds the script execution and returns anything is typed in the keyboard.<br />
<br />
Try this line in the Scilab console:<br />
<br />
-->x = input("x will be: ");<br />
x will be: 2<br />
<br />
-->x<br />
x =<br />
<br />
2.<br />
<br />
The value <b>2</b> was inserted from the keyboard, you can try any value and after use the variable <b>x</b> in following commands.<br />
<br />
If you want to input a string, there are two ways:<br />
<br />
single or double quotes when typing:<br />
<br />
-->x = input("x will be: ");<br />
x will be: 'hi'<br />
<br />
-->x<br />
x =<br />
<br />
hi <br />
<br />
-->x = input("x will be: ");<br />
x will be: "hello"<br />
<br />
-->x<br />
x =<br />
<br />
hello <br />
<br />
<br />
Or, you can use a second argument <b>"string"</b>:<br />
<br />
-->x = input("x will be: ", "string");<br />
x will be: yes!<br />
<br />
-->x<br />
x =<br />
<br />
yes!<br />
<br />
<br />
If you try to type text without single or double quotes, there will happen an error:<br />
<br />
-->x = input("x will be: ");<br />
x will be: test<br />
Undefined variable: test<br />
x will be: 0<br />
<br />
<br />
So, it's all!<br />
<br />
Let's stay using, studying and improving Scilab in 2015!<br />
<br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com2tag:blogger.com,1999:blog-9101701713138538731.post-75689591547329174562014-10-08T09:53:00.000-03:002014-10-08T09:53:05.066-03:00Native Function for Parsing String to Math Expression<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://usingscilab.blogspot.com/2013/11/parsing-string-to-math-expression-with.html">My last post</a> was about parsing strings to math functions, like:<br />
<br />
<span style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.2000007629395px;">parsingStr2Arithmetics("2+2")</span><br style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.2000007629395px;" /><span style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.2000007629395px;"> ans =</span><br style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.2000007629395px;" /><br style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.2000007629395px;" /><span style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.2000007629395px;"> 4. </span><br />
<br />
But, Scilab has a native function that evaluates strings:<br />
<br />
<div style="text-align: center;">
evstr()</div>
<br />
There are some examples using this function:<br />
<br />
-->evstr("1")<br />
ans =<br />
<br />
1. <br />
<br />
-->evstr("1+1")<br />
ans =<br />
<br />
2. <br />
<br />
-->evstr("2*(1+8)/3")<br />
ans =<br />
<br />
6.<br />
<br />
-->evstr("2*(1+1)")<br />
ans =<br />
<br />
4. <br />
<br />
-->evstr("2*(1+1) a")<br />
%val=[2*(1+1) a;<br />
!--error 4<br />
Variável indefinida: a<br />
in execstr instruction called by : <br />
at line 35 of function evstr called by : <br />
evstr("2*(1+1) a")<br />
<br />
<br />
Take a look that last example ahs failed, it happened because the argument "2*(1+1) a" does not mean a valid expression.<br />
<br />
Thus, there is a optimized way to do this task and work with strings which mean math expressions.<br />
<br />
Another useful use for this function is to use it for running another functions, for example:<br />
<br />
-->evstr("exp(1)")<br />
ans =<br />
<br />
2.7182818 <br />
<br />
-->evstr("sin(%pi/2)")<br />
ans =<br />
<br />
1. <br />
<br />
-->evstr("zeros(5, 5)")<br />
ans =<br />
<br />
0. 0. 0. 0. 0. <br />
0. 0. 0. 0. 0. <br />
0. 0. 0. 0. 0. <br />
0. 0. 0. 0. 0. <br />
0. 0. 0. 0. 0.<br />
<br />
To put a string in the argument, there is needed to use an inside single quote ', like this:<br />
<br />
-->"'"my string'""<br />
ans =<br />
<br />
"my string" <br />
<br />
<br />
So, the function evstr() may evaluate strings with other strings inside, like this:<br />
<br />
-->evstr("'"my'"+ '" string'"")<br />
ans =<br />
<br />
my string <br />
<br />
-->evstr("length('"test'")")<br />
ans =<br />
<br />
4. <br />
<br />
-->evstr("strsplit('"this is a string inside'", '" '")")<br />
ans =<br />
<br />
!this !<br />
! !<br />
!is !<br />
! !<br />
!a !<br />
! !<br />
!string !<br />
! !<br />
!inside !<br />
<br />
Think out of the box, strings may mean math and any other functions or sentence!<br />
<br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com2tag:blogger.com,1999:blog-9101701713138538731.post-10231137312003251942013-11-06T11:29:00.002-03:002013-11-06T11:29:39.802-03:00Parsing string to math expression with inline function<div dir="ltr" style="text-align: left;" trbidi="on">
This week, I discovered a new math game for Android: Match The Math (<a href="https://play.google.com/store/apps/details?id=com.engcross.matchthemath">https://play.google.com/store/apps/details?id=com.engcross.matchthemath</a>).<br />
<br />
I have seen this app converts a string to a math expression and solves it in real-time. So I though about how doing it in Scilab, to get a string like <i>"2*5 + 2"</i> and return the number that corresponds to the result of the expression, in the example <i>12</i> (<i>= 2*5 + 2</i>).<br />
<br />
Scilab has an interesting way to create "one line" functions, e. g. <i>sum2numbers(a,b)</i> where this function should return just <i>a+b</i>. This way is called inline functions and is defined like following:<br />
<br />
deff('[x]=func(a,b)', 'x=a+b');<br />
<br />
Where <i>'[x]=func(a,b)'</i> defines the structure of the function with <i>x</i> being the return, <i>func</i> is the name of the function and <i>a</i> and b are the arguments; <i>'x=a+b'</i> is what the function executes when is called: <i>x=a+b</i>.<br />
<br />
With this concept in mind, we can use a inline function to parse a string to a arithmetic expression because deff() uses only strings as arguments.<br />
<br />
Let's use a common function definition, with a string to be parsed as argument, and one inline function inside:<br />
<br />
<i>function [x]=parsingStr2Arithmetics(s) <span style="color: lime;">// definition of the function</span><br />deff('[x]=f()', 'x='+s); <span style="color: lime;">// creates inline function that parses the string</span><br />x = f(); <span style="color: lime;">// calls the function to return it result</span><br />endfunction; <span style="color: lime;">//end of the function</span></i><br />
<br />
<br />
Now our function is ready, we can test it using different expressions as arguments.<br />
<br />
-->parsingStr2Arithmetics("2")<br /> ans =<br /><br /> 2. <br /><br />-->parsingStr2Arithmetics("2+2")<br /> ans =<br /><br /> 4. <br /><br />-->parsingStr2Arithmetics("2+2*5")<br /> ans =<br /><br /> 12. <br />
-->parsingStr2Arithmetics("(2+2)*5")<br /> ans =<br /><br /> 20. <br /><br />-->parsingStr2Arithmetics("(2+2)*5 - 3")<br /> ans =<br /><br /> 17. <br />
<br />
<br />
For finishing this post, I recommend you to try Match The Math game, it's really cool and improves our math and problems solving skills.<br />
<br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com3tag:blogger.com,1999:blog-9101701713138538731.post-22110947951743709062013-10-08T16:07:00.001-03:002013-10-08T16:07:53.187-03:00Scilab as supporting software for mobile<div dir="ltr" style="text-align: left;" trbidi="on">
In <a href="http://engcross.blogspot.com.br/">Eng Cross' blog</a> we can see some apps those have Computer Vision features. I have known OpenCV, <a href="http://opencv.org/">Open Computer Vision API</a>, has a wrapper for Android, which is used by Eng Cross in his apps.<br />
<br />
Nowadays, there are information about two apps:<br />
<br />
4 Views<br />
<br />
This app applies four different effects in camera's image and composes a new image where the user can select one effect to be applied to the image and save pictures in Pictures directory.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv3aMAkUKtvFfwDp6JcW1vqlwYR_SXACJYPuaB48rLCgU7spZFKL56xoJ10yr3SD9W6r9PXYlYOGhJOzOm3kA_AdpSfVc4MtDTwaubha33bOYPbHay1DMRovpdcm9wp2cj0Bk_HH_e2hv7/s1600/4Views_device-2013-06-26-202548.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv3aMAkUKtvFfwDp6JcW1vqlwYR_SXACJYPuaB48rLCgU7spZFKL56xoJ10yr3SD9W6r9PXYlYOGhJOzOm3kA_AdpSfVc4MtDTwaubha33bOYPbHay1DMRovpdcm9wp2cj0Bk_HH_e2hv7/s320/4Views_device-2013-06-26-202548.png" width="320" /></a></div>
<br />
<br />
Right Angle<br />
<br />
This app creates a "L" mark in the center of the screen and identifies any right angle aligned with the mark holding the screen and pointing the vertex of the angle.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhptRNy3f3QgJf5lnnJZfe0ePWpQ2kcV5A3LkifOT3hRYleXb8Ee2bBQ55byjVPL3AlZihJ2ERbkHOXYxsKxqjXblXqlAMkpGsdbjlpqoJ1fb8zllwDC0PbratQgZTqolLx9iCtNabIRgs7/s1600/Right_Angle-device-2013-06-26-202048.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhptRNy3f3QgJf5lnnJZfe0ePWpQ2kcV5A3LkifOT3hRYleXb8Ee2bBQ55byjVPL3AlZihJ2ERbkHOXYxsKxqjXblXqlAMkpGsdbjlpqoJ1fb8zllwDC0PbratQgZTqolLx9iCtNabIRgs7/s320/Right_Angle-device-2013-06-26-202048.png" width="320" /></a></div>
<br />
<br />
But, what's the relation between these Android apps with Scilab?<br />
<br />
Scilab has the toolbox SIVp (Scilab Image and Video Processing toolbox) that can be used for testing similar algorithms. Once developing codes in Scilab is much faster than in any programming language, it's very useful to use this simulation environment for making first tests and validations of advanced algorithms, like computer vision, image/signal processing, statistics analysis, math modeling, etc.<br />
<br />
Added to being an simulation environment, Scilab can work as server for high intensive processing solutions, concentrating information, e. g. from sensors, and sharing data to mobile devices through webservices, like using <a href="http://usingscilab.blogspot.com.br/2013/08/json-in-scilab.html">JSON</a>.<br />
<br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com1tag:blogger.com,1999:blog-9101701713138538731.post-45915993732447452592013-08-14T17:19:00.000-03:002013-08-14T17:19:05.669-03:00JSON in Scilab<div dir="ltr" style="text-align: left;" trbidi="on">
Hi dears, today I've met a tool for Scilab that makes possible to handle JSON files into Scilab code. This tool is available through ATOMS or in <a href="http://forge.scilab.org/index.php/p/json/">http://forge.scilab.org/index.php/p/json/</a><br />
<br />
Once installed, let's make a simple test with this tool just for validation.<br />
<br />
First, it's created a json file (json_test.json) like below:<br />
<br />
{<br /> "orderID": 12345,<br /> "softwareName": "Scilab",<br /> "ToolName": "JSon",<br /> "contents": [<br /> {<br /> "productID": 1,<br /> "productName": "Test1",<br /> "quantity": 1<br /> },<br /> {<br /> "productID": 2,<br /> "productName": "Test2",<br /> "quantity": 3<br /> }<br /> ],<br /> "demoCompleted": true<br />}<br />
<a href="http://www.blogger.com/blogger.g?blogID=9101701713138538731" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><br />
<br />
Now, it's needed to get this file into Scilab, what we can do uding mgetl(.) function:<br />
<br />
<pre style="font-family: Monospaced; font-size: 12.0; font-style: normal;"><span style="color: black;">json_test</span> <span style="color: #5c5c5c;">=</span> <span style="color: #32b9b9;">mgetl</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">"</span><span style="color: rosybrown;">file_test.json</span><span style="color: rosybrown;">"</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span></pre>
<br />
Take attention for the path of the file.<br />
<br />
And the function JSONParse(.) returns the struct that corresponds to the data in the file, like this:<br />
<br />
<pre style="font-family: Monospaced; font-size: 12.0; font-style: normal;"><span style="color: black;">mystruct</span> <span style="color: #5c5c5c;">=</span> <span style="color: #ae5cb0; text-decoration: underline;">JSONParse</span><span style="color: #4a55db;">(</span><span style="color: black;">json_test</span><span style="color: #4a55db;">)</span></pre>
<br />
The expected result is<br />
<br />
-->mystruct<br /> mystruct =<br /><br /> orderID: 12345<br /> softwareName: "Scilab"<br /> ToolName: "JSon"<br /> contents: [1x2 struct]<br /> demoCompleted: "%T"<br />
<br />
<br />
For accessing the fields, try this:<br />
<br />
<a href="http://www.blogger.com/blogger.g?blogID=9101701713138538731" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a>-->mystruct.orderID<br /> ans =<br /><br /> 12345. <br /><br />-->mystruct.ToolName<br /> ans =<br /><br /> JSon <br /><br />-->mystruct.contents.productName<br /> ans =<br /><br /><br /> ans(1)<br /><br /> Test1 <br /><br /> ans(2)<br /><br /> Test2 <br /><br />
<br />
<br />
JSON is like XML pattern, much used for WebServices and in other Internet cases. Thus, I recommend to spend a few time taking a look about this technology and how Scilab can aggregate value to your solutions.<br />
<br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com1tag:blogger.com,1999:blog-9101701713138538731.post-85266527281912696792013-07-01T12:26:00.001-03:002013-07-01T14:12:47.245-03:00Plotting conical curves - circles<div dir="ltr" style="text-align: left;" trbidi="on">
Conical curves are very known geometric spaces based on section of cones. There are four conical curves:<br />
<ul style="text-align: left;">
<li>circle;</li>
<li>ellipse;</li>
<li>hyperbole;</li>
<li>parabola.</li>
</ul>
<br />
All of them are very used in computer graphics and, in this post, I wish to present how to plot a circle.<br />
<br />
The analytic equation of circles is: <i><b>(x - xc)² + (y - yc)² = r²</b></i> where <b><i>(xc, yc)</i></b> means the center of the circle and <i><b>r</b></i> is it radius.<br />
<br />
We know <i><b>cos²(a) + sin²(a) = 1</b></i>, for any angle <i><b>a</b></i>, thus multiplying both sides of equation by <b><i>r²</i></b> we obtain <i><b>(r cos(a))² + (r sin(a))² = r²</b></i>.<span id="goog_1082444719"></span><span id="goog_1082444720"></span><span id="goog_1082444717"></span><span id="goog_1082444718"></span><span id="goog_1082444715"></span><span id="goog_1082444716"></span><span id="goog_1082444713"></span><span id="goog_1082444714"></span><span id="goog_1082444711"></span><span id="goog_1082444712"></span><span id="goog_1082444709"></span><span id="goog_1082444710"></span><span id="goog_1082444707"></span><span id="goog_1082444708"></span><span id="goog_1082444705"></span><br />
<br />
Comparing original equation with obtained equation, it's possible to verify that:<br />
<br />
<b><i>x - xc = r cos (a)</i></b><br />
<b><i>x = r cos(a) + xc</i></b><br />
<br />
<i><b>y - yc = r sin(a)</b></i><br />
<i><b>y = r sin(a) + yc</b></i><br />
<br />
<br />
So, we have now the values for <i><b>x</b></i> and <b><i>y</i></b> depending only of the center of the circle, it radius and an angle <i><b>a</b></i>.<br />
<br />
<i><b>(xc, yc)</b></i> and <b><i>r</i></b> are given by the circle and <i><b>a</b></i> is an angle that means a dummy variable in range <b><i>[0, 2*%pi]</i></b>.<br />
<br />
<br />
Now, let's write some code in Scilab.<br />
<br />
By first, a circle of radius <i><b>r = 2</b></i> and center <b><i>(xc, yc) = (0, 0)</i></b>.<br />
<br />
<br />
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">//center of the circle</span>
<span style="color: black;">xc</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0</span><span style="color: black;">;</span>
<span style="color: black;">yc</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//radius of the circle</span>
<span style="color: black;">r</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">2</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//dummy variable for angle in range [0, 2*%pi]</span>
<span style="color: black;">a</span> <span style="color: #5c5c5c;">=</span> <span style="color: #ae5cb0; text-decoration: underline;">linspace</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">0</span><span style="color: black;">,</span> <span style="color: rosybrown;">2</span><span style="color: #5c5c5c;">*</span><span style="color: orchid;">%pi</span><span style="color: black;">,</span> <span style="color: rosybrown;">100</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//x axis</span>
<span style="color: black;">x</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">xc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">cos</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//y axis</span>
<span style="color: black;">y</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">yc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">sin</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//plot the circle</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: black;">x</span><span style="color: black;">,</span> <span style="color: black;">y</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span></pre>
<br />
<br />
The result of this code is the following picture.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBrewv4DsMQFDSD7OOugfkACe2TVCgLsp2U5BBZyQbcDvWpRNpWVSQt7omCn18G6WlIybawQXtXfoyrGVb5h9_eCCF36LiXdqqrCVNQtzpqQoCRFV2UKoxHtEMNjVqH0BkZrlMSIm0IFI5/s610/circle.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBrewv4DsMQFDSD7OOugfkACe2TVCgLsp2U5BBZyQbcDvWpRNpWVSQt7omCn18G6WlIybawQXtXfoyrGVb5h9_eCCF36LiXdqqrCVNQtzpqQoCRFV2UKoxHtEMNjVqH0BkZrlMSIm0IFI5/s320/circle.png" width="320" /></a></div>
Take attention the limits of the circle are <i><b>(-2, 2)</b></i> both for <b><i>x</i></b> and <i><b>y</b></i> axis, what means this circle is centered in <i><b>(0,0)</b></i> with radius <b><i>2</i></b>.<br />
<br />
<br />
And for finishing, a harder example, four circles with different centers and radius.<br />
<br />
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">/////////////////////////////////////////</span>
<span style="color: #01a801; font-style: italic;">//center of the circle</span>
<span style="color: black;">xc</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">6</span><span style="color: black;">;</span>
<span style="color: black;">yc</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//radius of the circle</span>
<span style="color: black;">r</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">6</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//dummy variable for angle in range [0, 2*%pi]</span>
<span style="color: black;">a</span> <span style="color: #5c5c5c;">=</span> <span style="color: #ae5cb0; text-decoration: underline;">linspace</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">0</span><span style="color: black;">,</span> <span style="color: rosybrown;">2</span><span style="color: #5c5c5c;">*</span><span style="color: orchid;">%pi</span><span style="color: black;">,</span> <span style="color: rosybrown;">100</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//x axis</span>
<span style="color: black;">x</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">xc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">cos</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//y axis</span>
<span style="color: black;">y</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">yc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">sin</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//plot the circle</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: black;">x</span><span style="color: black;">,</span> <span style="color: black;">y</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">////////////////////////////////////////</span>
<span style="color: #01a801; font-style: italic;">//center of the circle</span>
<span style="color: black;">xc</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">6</span><span style="color: black;">;</span>
<span style="color: black;">yc</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//radius of the circle</span>
<span style="color: black;">r</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">2</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//dummy variable for angle in range [0, 2*%pi]</span>
<span style="color: black;">a</span> <span style="color: #5c5c5c;">=</span> <span style="color: #ae5cb0; text-decoration: underline;">linspace</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">0</span><span style="color: black;">,</span> <span style="color: rosybrown;">2</span><span style="color: #5c5c5c;">*</span><span style="color: orchid;">%pi</span><span style="color: black;">,</span> <span style="color: rosybrown;">100</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//x axis</span>
<span style="color: black;">x</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">xc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">cos</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//y axis</span>
<span style="color: black;">y</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">yc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">sin</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//plot the circle</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: black;">x</span><span style="color: black;">,</span> <span style="color: black;">y</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">////////////////////////////////////////</span>
<span style="color: #01a801; font-style: italic;">//center of the circle</span>
<span style="color: black;">xc</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">2</span><span style="color: black;">;</span>
<span style="color: black;">yc</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//radius of the circle</span>
<span style="color: black;">r</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">2</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//dummy variable for angle in range [0, 2*%pi]</span>
<span style="color: black;">a</span> <span style="color: #5c5c5c;">=</span> <span style="color: #ae5cb0; text-decoration: underline;">linspace</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">0</span><span style="color: black;">,</span> <span style="color: rosybrown;">2</span><span style="color: #5c5c5c;">*</span><span style="color: orchid;">%pi</span><span style="color: black;">,</span> <span style="color: rosybrown;">100</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//x axis</span>
<span style="color: black;">x</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">xc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">cos</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//y axis</span>
<span style="color: black;">y</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">yc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">sin</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//plot the circle</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: black;">x</span><span style="color: black;">,</span> <span style="color: black;">y</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">////////////////////////////////////////</span>
<span style="color: #01a801; font-style: italic;">//center of the circle</span>
<span style="color: black;">xc</span> <span style="color: #5c5c5c;">=</span> <span style="color: #5c5c5c;">-</span><span style="color: rosybrown;">3</span><span style="color: black;">;</span>
<span style="color: black;">yc</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">3</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//radius of the circle</span>
<span style="color: black;">r</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">3</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//dummy variable for angle in range [0, 2*%pi]</span>
<span style="color: black;">a</span> <span style="color: #5c5c5c;">=</span> <span style="color: #ae5cb0; text-decoration: underline;">linspace</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">0</span><span style="color: black;">,</span> <span style="color: rosybrown;">2</span><span style="color: #5c5c5c;">*</span><span style="color: orchid;">%pi</span><span style="color: black;">,</span> <span style="color: rosybrown;">100</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//x axis</span>
<span style="color: black;">x</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">xc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">cos</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//y axis</span>
<span style="color: black;">y</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">yc</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">r</span><span style="color: #5c5c5c;">*</span><span style="color: #32b9b9;">sin</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #01a801; font-style: italic;">//plot the circle</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: black;">x</span><span style="color: black;">,</span> <span style="color: black;">y</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span></pre>
<br />
And the result is:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIGKOmRm_udotYTFARQ8rXYJAertA3CjucvXPWKP77vTJGpFKxzWuc_f_V7jWl_HH77_Fw2nqhiI7J7EHtyHgavg_Pcby1Y9uvvKE4tGocomSSlF4tFQgbsuNxe9iPusgLZT3XGVEx0inn/s767/circles.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="191" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIGKOmRm_udotYTFARQ8rXYJAertA3CjucvXPWKP77vTJGpFKxzWuc_f_V7jWl_HH77_Fw2nqhiI7J7EHtyHgavg_Pcby1Y9uvvKE4tGocomSSlF4tFQgbsuNxe9iPusgLZT3XGVEx0inn/s320/circles.png" width="320" /></a></div>
<br />
Take attention the parameters of center and radius of each circle and the obtained picture.<br />
<br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com4tag:blogger.com,1999:blog-9101701713138538731.post-51202069542050524572013-04-09T14:20:00.001-03:002013-04-10T10:56:23.147-03:00Analytical derivation with Scilab<div dir="ltr" style="text-align: left;" trbidi="on">
Today, I have discovered one useful function in Scilab, the derivat() function that works with expressions like<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2dwSnt26ydQ-y-uUo578brxasfI9W44YsAsIqDoUkey78k2DuGOUACPDOBoFFKsyrZLi-ZCP2q_rcLMZKh3vIKtc9c8c_BS7phT_F8f1ODwtd3VltYOfDbWvTQl00liJX6qJSaCRUW8p1/s1600/poly.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2dwSnt26ydQ-y-uUo578brxasfI9W44YsAsIqDoUkey78k2DuGOUACPDOBoFFKsyrZLi-ZCP2q_rcLMZKh3vIKtc9c8c_BS7phT_F8f1ODwtd3VltYOfDbWvTQl00liJX6qJSaCRUW8p1/s1600/poly.PNG" /></a></div>
which consists of functions of linear combinations with integer exponents of one variable (in the example denoted by <b><i>z</i></b>).<br />
<br />
The function derivat() implements the analytical derivation of p(z), giving the following result:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaxC7EknGQC6LTlK8XjgCvM2HYEx1XtblXnDcxhXya11qXK0_DKMLscruJEcp6cTMfTTENq4zhm-7TNJ6mM34lsuugWt-Tw0TJvEG8bYpgLT2kCvAtsRFFl0EA51kiUFODdjeIQbsGaDH_/s1600/poly_derivat.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaxC7EknGQC6LTlK8XjgCvM2HYEx1XtblXnDcxhXya11qXK0_DKMLscruJEcp6cTMfTTENq4zhm-7TNJ6mM34lsuugWt-Tw0TJvEG8bYpgLT2kCvAtsRFFl0EA51kiUFODdjeIQbsGaDH_/s1600/poly_derivat.PNG" /></a></div>
<br />
We can create this kind of expression with Scilab function poly(), like this:<br />
-->p1 = poly([1 -2 1], 'x', 'coef')<br />
p1 =<br />
<br />
2 <br />
1 - 2x + x <br />
<br />
-->p2 = poly([1 -4 2], 'y', 'coef')<br />
p2 =<br />
<br />
2 <br />
1 - 4y + 2y <br />
<br />
-->p3 = poly(ones(1, 10), 'z', 'coef')<br />
p3 =<br />
<br />
2 3 4 5 6 7 8 9 <br />
1 + z + z + z + z + z + z + z + z + z <br />
<br />
-->p4 = poly([-1 1], 't', 'roots')<br />
p4 =<br />
<br />
2 <br />
- 1 + t<br />
<br />
-->s = %s; p5 = s^{-1} + 2 + 3*s<br />
p5 =<br />
<br />
2 <br />
1 + 2s + 3s <br />
----------- <br />
s <br />
<br />
<br />
And so on.<br />
<br />
<br />
Now, the derivat() function implements the analytical derivation of the given functions:<br />
<br />
-->derivat(p1)<br />
ans =<br />
<br />
- 2 + 2x <br />
<br />
-->derivat(p2)<br />
ans =<br />
<br />
- 4 + 4y <br />
<br />
-->derivat(p3)<br />
ans =<br />
<br />
2 3 4 5 6 7 8 <br />
1 + 2z + 3z + 4z + 5z + 6z + 7z + 8z + 9z <br />
<br />
-->derivat(p4)<br />
ans =<br />
<br />
2t <br />
<br />
-->derivat(p5)<br />
ans =<br />
<br />
2 <br />
- 1 + 3s <br />
------ <br />
2 <br />
s <br />
<br />
<br />
There is a way for applying your knowledge about linear systems with a powerful open source simulation tool.</div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-4010422007207653432013-04-04T13:22:00.000-03:002013-04-04T13:22:09.809-03:00Creation of artifical data for classification tests<div dir="ltr" style="text-align: left;" trbidi="on">
In this semester, I'm teaching Artificial Intelligence discipline, and we are studying algorithms of classifying: Decision Trees and Neural Networks.<br />
<br />
One important task of the discipline is to test the developed algorithm and estimate it accuracy. For that, I use to create artificial data which is controlled and simple to analyze.<br />
<br />
The data consists of one table of N columns and many rows (let's use M rows). N - 1 first ones columns are of input data and the last column means the label (target), like presented below.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0BiJ3YL3NDx4hQoOTM-ZIntrUMzE_UPyNaRzCkc0WaTDcMENobGTEwymSqT9XimgA08jCFfXgnnJkIJwTJiwZYphnuLHO4P7NGdbRziRaDCECvcVPe3obHUDxpirFVDI0BzTXtrgLabM_/s1600/data_IA.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="281" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0BiJ3YL3NDx4hQoOTM-ZIntrUMzE_UPyNaRzCkc0WaTDcMENobGTEwymSqT9XimgA08jCFfXgnnJkIJwTJiwZYphnuLHO4P7NGdbRziRaDCECvcVPe3obHUDxpirFVDI0BzTXtrgLabM_/s320/data_IA.PNG" width="320" /></a></div>
The variable <b>x</b> presented is a matrix (table) with 5 columns and 20 rows. Being 4 columns of input data and the last column a label for each row.<br />
<br />
Label data are in a subset of natural numbers {1, 2, 3, 4, ....}, in the presented case {1, 2} where 1 means one class and 2 means the other.<br />
<br />
N - 1 first columns are created through rand() function using M/P rows for each class of data, with it we created a equal distributed data set for classes representativeness (P means how many classes are in the data set).<br />
<br />
For the variable <b>x</b> presented, it was created like following.<br />
<br />
-->n = 10;<br /><br />-->x = [[rand(n, 1); rand(n, 1) + 0.9] [1 + 2*rand(n, 1); rand(n, 1)*0.5 + 0.65] [rand(n, 1, "normal"); rand(n, 1) + 2.5] [rand(n, 1, "normal") - 2; rand(n, 1, "normal") + 2] [ones(n, 1); 2*ones(n, 1)]];<br />
<br />
But it's possible to use only simpler forms of combined columns for creating overlapped input data.<br />
<br />
Once created the matrix, we can write it to a file:<br />
<br />
<a href="http://www.blogger.com/blogger.g?blogID=9101701713138538731" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=9101701713138538731" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=9101701713138538731" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a>-->write("my_data.txt", x);<br />
<br />
<br />
And later we can read the data again to a variable:<br />
<br />
-->y = read("my_data.txt", -1, N);<br />
<br />
Take a look at<br />
<br />
<a href="http://usingscilab.blogspot.com.br/2009/03/using-files.html">http://usingscilab.blogspot.com.br/2009/03/using-files.html</a><br />
<br />
<a href="http://usingscilab.blogspot.com.br/2009/08/basic-statistic.html">http://usingscilab.blogspot.com.br/2009/08/basic-statistic.html</a><br />
<br />
<a href="http://usingscilab.blogspot.com.br/2011/02/statistics-operators-mean-and-stdev.html">http://usingscilab.blogspot.com.br/2011/02/statistics-operators-mean-and-stdev.html</a><br />
<br />
<a href="http://usingscilab.blogspot.com.br/search/label/matrix">http://usingscilab.blogspot.com.br/search/label/matrix</a><br />
<br />
for more details. <br />
<br />
<br />
</div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-48814368251698014372013-02-04T12:57:00.002-03:002013-02-04T12:57:39.393-03:002D Rotation<div dir="ltr" style="text-align: left;" trbidi="on">
Let's make a rotation of a square. First, we create the square:<br />
<br />
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: black;">A</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: rosybrown;">0</span><span style="color: black;">,</span> <span style="color: rosybrown;">0</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span>
<span style="color: black;">B</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: rosybrown;">1</span><span style="color: black;">,</span> <span style="color: rosybrown;">0</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span>
<span style="color: black;">C</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: rosybrown;">1</span><span style="color: black;">,</span> <span style="color: rosybrown;">1</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span>
<span style="color: black;">D</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: rosybrown;">0</span><span style="color: black;">,</span> <span style="color: rosybrown;">1</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span>
<span style="color: black;">sq</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: black;">A</span><span style="color: black;">;</span>
<span style="color: black;">B</span><span style="color: black;">;</span>
<span style="color: black;">C</span><span style="color: black;">;</span>
<span style="color: black;">D</span><span style="color: black;">;</span>
<span style="color: black;">A</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span>
<span style="color: #32b9b9;">plot2d</span><span style="color: #4a55db;">(</span><span style="color: black;">sq</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">1</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: black;">sq</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: black;">rect</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: #5c5c5c;">-</span><span style="color: rosybrown;">.1</span> <span style="color: #5c5c5c;">-</span><span style="color: rosybrown;">.1</span> <span style="color: rosybrown;">1.1</span> <span style="color: rosybrown;">1.1</span><span style="color: #4a55db;">]</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span><span style="color: black;"></span></pre>
<br />
The result is the following picture.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ9BoZedUGmzAFbT7VhkrXscqBw3HJ5SJpLrcriIcZcOEfigsBxiZVKNjD4y3CEaa9BrxlJaj8dIT1pk-dWuyfpyGhobWN7UZ4fxb8KXZtHb9BdSpQ4X5t9jcXjI8DS1IicjxR1WJApaSe/s1600/rot_square.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ9BoZedUGmzAFbT7VhkrXscqBw3HJ5SJpLrcriIcZcOEfigsBxiZVKNjD4y3CEaa9BrxlJaj8dIT1pk-dWuyfpyGhobWN7UZ4fxb8KXZtHb9BdSpQ4X5t9jcXjI8DS1IicjxR1WJApaSe/s320/rot_square.png" width="320" /></a></div>
<br />
<br />
For rotating this object an angle a = pi/4 (45°), we can do<br />
<br />
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: black;">a</span> <span style="color: #5c5c5c;">=</span> <span style="color: orchid;">%pi</span><span style="color: #5c5c5c;">/</span><span style="color: rosybrown;">4</span><span style="color: black;">;</span>
<span style="color: black;">r</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: #32b9b9;">cos</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span> <span style="color: #5c5c5c;">-</span><span style="color: #32b9b9;">sin</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #32b9b9;">sin</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span> <span style="color: #32b9b9;">cos</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span>
<span style="color: black;">sq_r</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">sq</span><span style="color: #5c5c5c;">*</span><span style="color: black;">r</span><span style="color: black;">;</span>
<span style="color: #32b9b9;">plot2d</span><span style="color: #4a55db;">(</span><span style="color: black;">sq_r</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">1</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: black;">sq_r</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span><span style="color: black;"></span></pre>
<br />
The result is<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ2ph5uBHEk_440qrvmJB7o4KsQvnM9QbVFQiRVixfPMkY718vXG1YPbyWHU6oGE-OP_28XT6HlvYg52XQRUSmriHrYPmmxKYMltY7mdbqyUbQKo873WODwuMtdSruFBDxKt1PsD2nCpIq/s1600/rot_square_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ2ph5uBHEk_440qrvmJB7o4KsQvnM9QbVFQiRVixfPMkY718vXG1YPbyWHU6oGE-OP_28XT6HlvYg52XQRUSmriHrYPmmxKYMltY7mdbqyUbQKo873WODwuMtdSruFBDxKt1PsD2nCpIq/s320/rot_square_1.png" width="320" /></a></div>
<br />
The same technique can be done for rotation any kind of geometric structure.<br />
<br />
For another example, look a random structure and its rotation.<br />
<br />
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: black;">sq</span> <span style="color: #5c5c5c;">=</span> <span style="color: #32b9b9;">rand</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">10</span><span style="color: black;">,</span> <span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #32b9b9;">plot2d</span><span style="color: #4a55db;">(</span><span style="color: black;">sq</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">1</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: black;">sq</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: black;">rect</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: #5c5c5c;">-</span><span style="color: rosybrown;">.1</span> <span style="color: #5c5c5c;">-</span><span style="color: rosybrown;">.1</span> <span style="color: rosybrown;">1.1</span> <span style="color: rosybrown;">1.1</span><span style="color: #4a55db;">]</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: black;">a</span> <span style="color: #5c5c5c;">=</span> <span style="color: orchid;">%pi</span><span style="color: #5c5c5c;">/</span><span style="color: rosybrown;">4</span><span style="color: black;">;</span>
<span style="color: black;">r</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: #32b9b9;">cos</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span> <span style="color: #5c5c5c;">-</span><span style="color: #32b9b9;">sin</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #32b9b9;">sin</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span> <span style="color: #32b9b9;">cos</span><span style="color: #4a55db;">(</span><span style="color: black;">a</span><span style="color: #4a55db;">)</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span>
<span style="color: black;">sq_r</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">sq</span><span style="color: #5c5c5c;">*</span><span style="color: black;">r</span><span style="color: black;">;</span>
<span style="color: #32b9b9;">plot2d</span><span style="color: #4a55db;">(</span><span style="color: black;">sq_r</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">1</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: black;">sq_r</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: black;">style</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span></pre>
<br />
<br />
The result is<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq19j7Ak21wPhI3KuLFvArUA3b_8sgC9MoCdWfzxLbbFBqPKFHd_IRe7RyqnE1_GYuTSBpUmKEX4Y_N4LFvUwWnDZ-yXnkU38CgEE42OTWbmq-9ArI7O3tYtaFyU63XGtqUk7hHeqslMDt/s1600/rot_square_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq19j7Ak21wPhI3KuLFvArUA3b_8sgC9MoCdWfzxLbbFBqPKFHd_IRe7RyqnE1_GYuTSBpUmKEX4Y_N4LFvUwWnDZ-yXnkU38CgEE42OTWbmq-9ArI7O3tYtaFyU63XGtqUk7hHeqslMDt/s320/rot_square_2.png" width="320" /></a></div>
Take attention the presented rotation method rotates the object using the center of axes (point (0, 0)) as reference. However, it's very simple to change the point of reference just adjusting matrix <b>r</b>, can you do this?<br /><br />
</div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com1tag:blogger.com,1999:blog-9101701713138538731.post-87692699669073278262013-01-23T17:14:00.001-03:002013-01-23T17:15:06.752-03:00Equalis Introduces Advanced Image and Video Processing Module - Equalis - Where Engineering and Science Computes<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://www.equalis.com/?PR_12042012#.UQBDzcEMtA4.blogger">Equalis Introduces Advanced Image and Video Processing Module - Equalis - Where Engineering and Science Computes</a><br />
<br />
This a very interesting new for engineers, students and researchers who work with image processing and/or computer vision, like me.<br />
<br />
I hope to study something about this new module soon and I can support anyone else that intend to begin in this amazing area.<br />
<br />
Happy year of 2013 for everyone!</div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-31419321920043916252012-11-26T16:05:00.001-03:002012-11-26T16:39:26.122-03:00Queue simulation in Scilab<div dir="ltr" style="text-align: left;" trbidi="on">
This post is an answer for Agnes, who commented the last post: <br />
<h3 class="post-title entry-title" itemprop="name">
<a href="http://usingscilab.blogspot.com.br/2012/11/engineering-and-scientific-computing.html">Engineering and Scientific Computing with Scilab - Book</a></h3>
This script is a simple simulation of a queue of packs (or anything else) which there are a source, the queue and a destiny.<br />
<br />
I coded this script for simulating and problem where there is a source that sends packs with a specific probability, a queue that receives the source packs and stores them, with a maximum number of stored packs, and a destiny that receives the packs from the queue with another specific probability. <br />
<br />
All interested ones can run the code and comment it. <br />
<br />
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: black;">N_packs</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">15</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//total number of packs</span>
<span style="color: black;">P_send</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0.5</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//probability of a pack to be sent</span>
<span style="color: black;">P_process</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0.5</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//probability of a pack to be processed</span>
<span style="color: black;">N_queue</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">10</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//maximum number of elements in the queue</span>
<span style="color: black;">N_sent</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//number of packs sent to queue</span>
<span style="color: black;">N_line</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//number of packs in the queue</span>
<span style="color: black;">N_processed</span> <span style="color: #5c5c5c;">=</span> <span style="color: rosybrown;">0</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//number of packs processed</span>
<span style="color: black;">src</span> <span style="color: #5c5c5c;">=</span> <span style="color: #32b9b9;">rand</span><span style="color: #4a55db;">(</span><span style="color: black;">N_packs</span><span style="color: black;">,</span> <span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//source packs</span>
<span style="color: black;">dst</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//destiny packs</span>
<span style="color: black;">line</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//queue</span>
<span style="color: black;">processed</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//processed packs</span>
<span style="color: #a020f0;">while</span> <span style="color: black;">N_processed</span> <span style="color: #5c5c5c;"><</span> <span style="color: black;">N_packs</span><span style="color: black;">,</span>
<span style="color: #a020f0;">try</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: black;">src</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">1</span><span style="color: #4a55db;">)</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">N_queue</span> <span style="color: #5c5c5c;">+</span> <span style="color: rosybrown;">2</span><span style="color: black;">,</span> <span style="color: black;">src</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: rosybrown;">'</span><span style="color: rosybrown;">.g</span><span style="color: rosybrown;">'</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span><span style="color: #01a801; font-style: italic;"> </span></pre>
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">//plots source packs as green dots</span>
<span style="color: #a020f0;">end</span><span style="color: black;">;</span>
<span style="color: #a020f0;">try</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: black;">processed</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">1</span><span style="color: #4a55db;">)</span> <span style="color: #5c5c5c;">+</span> <span style="color: black;">N_queue</span> <span style="color: #5c5c5c;">+</span> <span style="color: rosybrown;">2</span><span style="color: black;">,</span> <span style="color: black;">processed</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: rosybrown;">'</span><span style="color: rosybrown;">*k</span><span style="color: rosybrown;">'</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span> </pre>
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">//plots the queue as line of blue dots</span>
<span style="color: #a020f0;">end</span><span style="color: black;">;</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">1</span><span style="color: #ffaa00;">:</span><span style="color: black;">N_queue</span><span style="color: black;">,</span> <span style="color: #32b9b9;">zeros</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">1</span><span style="color: black;">,</span> <span style="color: black;">N_queue</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: rosybrown;">'</span><span style="color: rosybrown;">.w</span><span style="color: rosybrown;">'</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span> <span style="color: #01a801; font-style: italic;">//clears queue dots</span>
<span style="color: #a020f0;">try</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: black;">line</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">1</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: black;">line</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: rosybrown;">'</span><span style="color: rosybrown;">.b</span><span style="color: rosybrown;">'</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span><span style="color: #01a801; font-style: italic;"> </span></pre>
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">//plots the queue as line of blue dots</span>
<span style="color: #a020f0;">end</span><span style="color: black;">;</span>
<span style="color: #a020f0;">try</span>
<span style="color: #ae5cb0; text-decoration: underline;">plot</span><span style="color: #4a55db;">(</span><span style="color: black;">dst</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">1</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: black;">dst</span><span style="color: #4a55db;">(</span><span style="color: #ffaa00;">:</span><span style="color: black;">,</span><span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">,</span> <span style="color: rosybrown;">'</span><span style="color: rosybrown;">.r</span><span style="color: rosybrown;">'</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span><span style="color: #01a801; font-style: italic;"> </span></pre>
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">//plots destiny packs as red dots</span>
<span style="color: #a020f0;">end</span><span style="color: black;">;</span>
<span style="color: #a020f0;">if</span> <span style="color: #32b9b9;">rand</span><span style="color: #4a55db;">(</span><span style="color: #4a55db;">)</span> <span style="color: #5c5c5c;"><</span> <span style="color: black;">P_send</span> <span style="color: #a020f0;">then</span><span style="color: #01a801; font-style: italic;"> </span></pre>
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">//sends a pack with P_send probability</span>
<span style="color: #a020f0;">if</span> <span style="color: #32b9b9;">and</span><span style="color: #4a55db;">(</span><span style="color: #4a55db;">[</span><span style="color: black;">N_line</span> <span style="color: #5c5c5c;"><</span> <span style="color: black;">N_queue</span> <span style="color: black;">N_sent</span> <span style="color: #5c5c5c;"><</span> <span style="color: black;">N_packs</span><span style="color: #4a55db;">]</span><span style="color: #4a55db;">)</span> <span style="color: #a020f0;">then</span><span style="color: #01a801; font-style: italic;"> </span></pre>
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">//verifies the queue is full or all packs have been sent</span>
<span style="color: black;">N_sent</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">N_sent</span> <span style="color: #5c5c5c;">+</span> <span style="color: rosybrown;">1</span><span style="color: black;">;</span>
<span style="color: black;">N_line</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">N_line</span> <span style="color: #5c5c5c;">+</span> <span style="color: rosybrown;">1</span><span style="color: black;">;</span>
<span style="color: black;">line</span><span style="color: #4a55db;">(</span><span style="color: black;">N_line</span><span style="color: black;">,</span><span style="color: #ffaa00;">:</span><span style="color: #4a55db;">)</span> <span style="color: #5c5c5c;">=</span> <span style="color: #4a55db;">[</span><span style="color: black;">N_line</span> <span style="color: rosybrown;">0</span><span style="color: #4a55db;">]</span><span style="color: black;">;</span>
<span style="color: black;">processed</span><span style="color: #4a55db;">(</span><span style="color: black;">N_sent</span><span style="color: black;">,</span><span style="color: #ffaa00;">:</span><span style="color: #4a55db;">)</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">src</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">1</span><span style="color: black;">,</span><span style="color: #ffaa00;">:</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: black;">src</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">src</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">2</span><span style="color: #ffaa00;">:</span><span style="color: #ffaa00;">$</span><span style="color: black;">,</span><span style="color: #ffaa00;">:</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #a020f0;">end</span>
<span style="color: #a020f0;">end</span>
<span style="color: #a020f0;">if</span> <span style="color: #32b9b9;">rand</span><span style="color: #4a55db;">(</span><span style="color: #4a55db;">)</span> <span style="color: #5c5c5c;"><</span> <span style="color: black;">P_process</span> <span style="color: #a020f0;">then</span><span style="color: #01a801; font-style: italic;"> </span></pre>
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">//processes a pack with P_process probability</span>
<span style="color: #a020f0;">if</span> <span style="color: black;">N_line</span> <span style="color: #5c5c5c;">></span> <span style="color: rosybrown;">0</span> <span style="color: #a020f0;">then</span><span style="color: #01a801; font-style: italic;"> </span></pre>
<pre style="font-family: Lucida Sans Typewriter; font-size: 14.0; font-style: normal;"><span style="color: #01a801; font-style: italic;">//verifies the line has at least one pack</span>
<span style="color: black;">N_processed</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">N_processed</span> <span style="color: #5c5c5c;">+</span> <span style="color: rosybrown;">1</span><span style="color: black;">;</span>
<span style="color: black;">N_line</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">N_line</span> <span style="color: #5c5c5c;">-</span> <span style="color: rosybrown;">1</span><span style="color: black;">;</span>
<span style="color: black;">line</span> <span style="color: #5c5c5c;">=</span> <span style="color: black;">line</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">1</span><span style="color: #ffaa00;">:</span><span style="color: black;">N_line</span><span style="color: black;">,</span><span style="color: #ffaa00;">:</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: black;">dst</span><span style="color: #4a55db;">(</span><span style="color: black;">N_processed</span><span style="color: black;">,</span><span style="color: #ffaa00;">:</span><span style="color: #4a55db;">)</span> <span style="color: #5c5c5c;">=</span> <span style="color: #5c5c5c;">-</span><span style="color: #32b9b9;">rand</span><span style="color: #4a55db;">(</span><span style="color: rosybrown;">1</span><span style="color: black;">,</span> <span style="color: rosybrown;">2</span><span style="color: #4a55db;">)</span><span style="color: black;">;</span>
<span style="color: #a020f0;">end</span>
<span style="color: #a020f0;">end</span>
<span style="color: #a020f0;">end</span></pre>
</div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-29172352317603316432012-11-16T17:26:00.002-03:002012-11-16T17:26:55.301-03:00Engineering and Scientific Computing with Scilab - Book<div dir="ltr" style="text-align: left;" trbidi="on">
I found this book today: <a href="http://books.google.com.br/books/about/Engineering_and_Scientific_Computing_Wit.html?id=mpkznLUemMoC&redir_esc=y">Engineering and Scientific Computing with Scilab</a> and there is a very good reference for Scilab users and engineers in general.<br />
<br />
The beginning of the book has an introduction about Scilab software and how to use it. In Part II, the book contains information about a specific Systems and Control Toolbox for Scilab.<br />
<br />
Part III presents Applications, and here we can apply all knowledge to create and model real systems for simulation and/or real-time control.<br />
<br />
This kind of basis makes the difference in undergraduate studies, because the students can easily see and practice their theoretical concepts and improve their problems solving skills.<br />
<br />
Using a simulation environment, students can safely test any system and see what happen in many cases and different situations.<br />
<br />
So, everyone knows I'm a strong defender of simulations in engineering and all nature sciences, and a book like that is a great signal other people are investing time and work in the same ideal.<br />
<br />
However, we must hold in mind, simulation is only the beginning, but it can cut off many problems, specially in design process.</div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com4tag:blogger.com,1999:blog-9101701713138538731.post-10169733315028779302012-10-18T15:10:00.004-03:002012-10-18T15:10:33.899-03:00Scilab as software for engineers<div dir="ltr" style="text-align: left;" trbidi="on">
I'm an engineer (of telecommunications) and have used Scilab for several years (since 2005). There are many useful tools for image and signal processing, optimization, linear systems and transformations, and general simulations.<br />
<br />
Scilab is a software for numerical simulation supported by <a href="http://www.scilab.org/aboutus/consortium">Scilab Consortium</a>. This group of companies provides resources and services for users and other companies those intend to migrate to an open and stable software platform.<br />
<br />
Beyond formal support, Scilab Consortium is an open environment for doubts and discussions where everyone can help and be helped.<br />
<br />
About technical resources, Scilab has two ways for developing and application or simulation: script language (Scinotes) or drag-and-drop interface (Scicos), both are powerful but I believe script language is supported by more external toolboxes.<br />
<br />
Scilab external toolboxes are freeware and can be downloaded and installed through ATOMS tool (see next picture, click in the figure to enlarge it).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUcdkSXHCfEI0PREUaOYqsuGvkN3wLN4IBtb4phkGVii6ONCW5kG8dLBovzSh0X_9I8JNhN6onviV1xVyev2SDVCy7rI_YW0_5ZzpA2aH9UsLC_KPdVX2yKZNJZywrdACDU7lC_m-36Cot/s1600/ATOMS.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUcdkSXHCfEI0PREUaOYqsuGvkN3wLN4IBtb4phkGVii6ONCW5kG8dLBovzSh0X_9I8JNhN6onviV1xVyev2SDVCy7rI_YW0_5ZzpA2aH9UsLC_KPdVX2yKZNJZywrdACDU7lC_m-36Cot/s320/ATOMS.PNG" width="320" /></a></div>
<br />
Some links for posts I have published here about my fields of study:<br />
<br />
Matrices: <a href="http://usingscilab.blogspot.com.br/search/label/matrix">http://usingscilab.blogspot.com.br/search/label/matrix</a><br />
<br />
Scilab functions: <a href="http://usingscilab.blogspot.com.br/search/label/functions">http://usingscilab.blogspot.com.br/search/label/functions</a><br />
<br />
Fourier Transform: <a href="http://usingscilab.blogspot.com.br/search/label/fft">http://usingscilab.blogspot.com.br/search/label/fft</a><br />
<br />
Signal processing: <a href="http://usingscilab.blogspot.com.br/search/label/signal%20processing">http://usingscilab.blogspot.com.br/search/label/signal%20processing</a><br />
<br />
Image Processing: <a href="http://usingscilab.blogspot.com.br/search/label/image%20processing">http://usingscilab.blogspot.com.br/search/label/image%20processing</a><br />
<br />
Data visualization: <a href="http://usingscilab.blogspot.com.br/search/label/plot">http://usingscilab.blogspot.com.br/search/label/plot</a><br />
<br />
Statistics: <a href="http://usingscilab.blogspot.com.br/search/label/statistic">http://usingscilab.blogspot.com.br/search/label/statistic</a><br />
<br />
Mathematics: <a href="http://usingscilab.blogspot.com.br/search/label/math">http://usingscilab.blogspot.com.br/search/label/math</a><br />
<br />
<br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-76936203403957622252012-10-02T11:34:00.002-03:002012-10-02T11:36:30.372-03:00Plotting contours of surfaces<div dir="ltr" style="text-align: left;" trbidi="on">
I know there is very useful to see contours of surfaces, many areas use this kind of resource and Scilab has a very simple way to do that.<br />
<br />
For a first example, let's use the surface given by the function z = x² + y², this function is a 3D parable. Run the following code for making this surface's graph.<br />
<br />
<br />
x = -5:0.1:5;<br />
y = -5:0.1:5;<br />
<br />
[xx yy] = meshgrid(x, y);<br />
<br />
z = xx.^2 + yy.^2;<br />
<br />
plot3d(x, y, z);<br />
<br />
<br />
The generated graph is like this.<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwGJ7OZ3fAYpPDWUnx0-dOf5xcCwTIxjDBtkFh6s6V-OpMJd96zWYIjMvgT1c-PvGe6vjKDqbDHdCLsRXjnpmSAx6RQPyokNY_G6LLbtfUe_X-Rl1X8wUxqOgSxMaaAkDyUT8L4ZYTIIfv/s1600/3d_parable.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="173" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwGJ7OZ3fAYpPDWUnx0-dOf5xcCwTIxjDBtkFh6s6V-OpMJd96zWYIjMvgT1c-PvGe6vjKDqbDHdCLsRXjnpmSAx6RQPyokNY_G6LLbtfUe_X-Rl1X8wUxqOgSxMaaAkDyUT8L4ZYTIIfv/s320/3d_parable.png" width="320" /></a></div>
Now, let's see the contours of that surface. But, before, it's interesting to analyze the equation z = x² + y². If z is fixed in a constant value, we have x² + y² = const and this equation means a circle centered in the point (0, 0) and radius square of const.<br />
<br />
For plotting the contours, run this code:<br />
<br />
n_curves = 10;<br />
x = -5:0.1:5;<br />
y = -5:0.1:5;<br />
<br />
function z=my_surface(xx, yy),<br />
z=xx^2 + yy^2;<br />
endfunction<br />
<br />
contour(x, y, my_surface, n_curves);<br />
<br />
<br />
The result is presented following:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgngxK2jQgie63QJLeoNIfCeiT9jHkEceGQ7jvVwaMX_bx6uXO5CF0XukizSOV1F3ZUNl4f6fcfe7-yS1F2biKlyUIaCGRVwgoTUOTgD7cXwGn9RuqctevIrlFMGK8N8PiiIZWylLfLMJbt/s1600/parable_contourns.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="283" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgngxK2jQgie63QJLeoNIfCeiT9jHkEceGQ7jvVwaMX_bx6uXO5CF0XukizSOV1F3ZUNl4f6fcfe7-yS1F2biKlyUIaCGRVwgoTUOTgD7cXwGn9RuqctevIrlFMGK8N8PiiIZWylLfLMJbt/s320/parable_contourns.png" width="320" /></a></div>
In fact, we can see there are concentric circles centered in the point (0, 0).<br />
<br />
So, that's all folks!<br />
<br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-60246142220918176632012-09-19T15:52:00.000-03:002012-09-19T15:52:13.778-03:00Plot3d2: creating a cube<div dir="ltr" style="text-align: left;" trbidi="on">
For creating a cube with plot3d2(.) function it's required to create three matrices for mapping each vertex of the cube.<br />
<br />
Think the six faces of the cube, now open them on a plan and hold each vertex position of the cube. Empty elements of the matrix should be filled according spacial logic of the cube, with the same value of the neighbor vertexes.<br />
<br />
-->x = [zeros(4, 2), ones(4, 2), zeros(4, 1)]<br /> x =<br /><br /> 0. 0. 1. 1. 0. <br /> 0. 0. 1. 1. 0. <br /> 0. 0. 1. 1. 0. <br /> 0. 0. 1. 1. 0. <br /><br />-->y = ones(4, 5);<br /><br />-->y(2:3,2:3) = 0<br />
y =<br /><br /> 1. 1. 1. 1. 1. <br /> 1. 0. 0. 1. 1. <br /> 1. 0. 0. 1. 1. <br /> 1. 1. 1. 1. 1. <br /><br />
-->z = [zeros(2, 5); ones(2, 5)];<br />
z =<br /><br /> 0. 0. 0. 0. 0. <br /> 0. 0. 0. 0. 0. <br /> 1. 1. 1. 1. 1. <br /> 1. 1. 1. 1. 1. <br /><br />-->plot3d2(x, y, z);<br />
<br />
<br />
<br />
Result is presented in the following image:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp2UhhmiSDnsQV-hk3bLDJrdt634-DD0ftkGoEy1MeLF6ZqQei67hRtU3P_aWEjJD0cVhZ4o_Vs82H8EFXZ2B0Z8dW5u6LB9fZmuI7vipkh-Xi1ncMek16An6IBUXb858vmLD3gggxge2Z/s1600/cube.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp2UhhmiSDnsQV-hk3bLDJrdt634-DD0ftkGoEy1MeLF6ZqQei67hRtU3P_aWEjJD0cVhZ4o_Vs82H8EFXZ2B0Z8dW5u6LB9fZmuI7vipkh-Xi1ncMek16An6IBUXb858vmLD3gggxge2Z/s320/cube.png" width="320" /></a></div>
In this case, all faces of the cube are equal, which makes this structure symmetric.<br /><br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com2tag:blogger.com,1999:blog-9101701713138538731.post-37841346969904215992012-09-19T15:14:00.000-03:002012-09-19T15:53:40.308-03:00Plot3D: rectangular surface<div dir="ltr" style="text-align: left;" trbidi="on">
I received a request of how to create a rectangular surface.<br />
<br />
This post is about plot3d(.) function, which I use to create surfaces in Scilab: <a href="http://usingscilab.blogspot.com.br/2009/06/plot-3d-surface.html">http://usingscilab.blogspot.com.br/2009/06/plot-3d-surface.html</a><br />
<br />
Now, look plot3d(.) has three arguments: x, y, and z, being the first two ones vectors and the last one is a matrix.<br />
<br />
For a surface that x and y are in set [0, 10] and z is in set [0, 1], take the following code:<br />
<br />
-->x = 0:10;<br />
<br />
-->y = 0:10;<br />
<br />
-->z = zeros(length(x), length(y)); // z matrix is initialized with zeros<br />
<br />
-->z(($/4):(3*$/4),($/4):(3*$/4)) = 1 // a square in the matrix is set to 1<br />
z =<br />
<br />
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. <br />
0. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. <br />
0. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. <br />
0. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. <br />
0. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. <br />
0. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. <br />
0. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. <br />
0. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. <br />
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. <br />
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. <br />
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. <br />
<br />
-->plot3d(x, y, z); // shows the 3d graphic with x, y, and z components<br />
<br />
<br />
<br />
The generated image is the following.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUoXGVE5g2kTBSilBmMkRlGoM1hKgFzyEsPHrUpHgBoBJ8bDQ7eY1w7h-KWuNT4F8MnP_Mp-yxx27M0f7l6e2StS_E0KnNeo5hsNt3ibphb_cfvyliZ8T8PDAWX-r2P6wrH3PkJcbuXaxS/s1600/rect.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUoXGVE5g2kTBSilBmMkRlGoM1hKgFzyEsPHrUpHgBoBJ8bDQ7eY1w7h-KWuNT4F8MnP_Mp-yxx27M0f7l6e2StS_E0KnNeo5hsNt3ibphb_cfvyliZ8T8PDAWX-r2P6wrH3PkJcbuXaxS/s320/rect.png" width="320" /></a></div>
<br />
I wish this example has been helpful.<br />
<br />
Obs.: for creating a cube, or <span class="short_text" id="result_box" lang="en"><span class="hps">parallelogram, plot3d2(.) function is more recommended: <a href="http://usingscilab.blogspot.com.br/2012/09/plot3d2-creating-cube.html">http://usingscilab.blogspot.com.br/2012/09/plot3d2-creating-cube.html</a></span></span> <br />
<br /></div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-29199208048137284722012-09-03T11:42:00.000-03:002012-09-03T11:42:01.541-03:00Gamma function<div dir="ltr" style="text-align: left;" trbidi="on">
Last week I was teaching about combinatorial analysis and talking about factorial operator I remembered Gamma Function, this function is very useful in signal processing but particularly Gamma Function is equal to the factorial for non-negative integer numbers.<br />
<br />
Theory about Gamma Function is very well described in Wikipedia: <a href="http://en.wikipedia.org/wiki/Gamma_function">http://en.wikipedia.org/wiki/Gamma_function</a><br />
<br />
The equation that defines Gamma Function is<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://upload.wikimedia.org/math/d/2/c/d2c367a1ab40945b139fc49b9b467633.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://upload.wikimedia.org/math/d/2/c/d2c367a1ab40945b139fc49b9b467633.png" /></a></div>
<br />
Following figure presents the graph of Gamma Function<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://upload.wikimedia.org/wikipedia/commons/b/b3/Gamma_function_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="205" src="http://upload.wikimedia.org/wikipedia/commons/b/b3/Gamma_function_2.png" width="320" /></a></div>
<br />
<br />
And when <i>z</i> is a non-negative integer is verified that<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://upload.wikimedia.org/math/4/a/9/4a9edcc1b59de9550c04cfd24a3c28e7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://upload.wikimedia.org/math/4/a/9/4a9edcc1b59de9550c04cfd24a3c28e7.png" /></a></div>
<br />
This consequence is because of the property<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://upload.wikimedia.org/math/8/c/3/8c34a7461c9dbd619bc61c82bf599270.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://upload.wikimedia.org/math/8/c/3/8c34a7461c9dbd619bc61c82bf599270.png" /></a></div>
<br />
<br />
<br />
<br />
<br />
Typical values of Gamma function are<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://upload.wikimedia.org/math/5/7/d/57d2bfd84f81ef7a749fa455ce04a018.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://upload.wikimedia.org/math/5/7/d/57d2bfd84f81ef7a749fa455ce04a018.png" /></a></div>
In Scilab, there are both functions: gamma(.) and factorial(.), following are some examples of these functions<br />
<br />
<br />
-->factorial(1)<br /> ans =<br /><br /> 1. <br /><br />-->gamma(1)<br /> ans =<br /><br /> 1. <br />
<br />
-->factorial(1.5)<br /> !--error 10000 <br />factorial: Wrong value for input argument #1: Scalar/vector/matrix/hypermatrix of positive integers expected.<br />at line 14 of function factorial called by : <br />factorial(1.5)<br /><br /><br />-->gamma(1.5)<br /> ans =<br /><br /> 0.8862269 <br /><br />-->sqrt(%pi)/2<br /> ans =<br /><br /> 0.8862269 <br /><br />
Look factorial(.) is not possible to be applied in a non-integer number, the same happens with negative numbers.<br />
<br />
And gamma(.) in 1.5 is equal to sqrt(%pi)/2 verifying the correspondence presented in the typical values figure.<br />
<br />
<br />
Obs.: all equations and figures that I posted in this text were got from the Wikipedia page.</div>
Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-12437958271258262092012-05-25T16:14:00.000-03:002012-08-09T12:00:27.118-03:00Scilab Tips<div dir="ltr" style="text-align: left;" trbidi="on">
This week I discovered <a href="http://usingscilab.blogspot.com.br/2010/10/scilab-consortium-member.html">Equalis</a> has a portal for Scilab users shared tips and examples of applications: <a href="http://www.equalis.com/blogpost/731635/Scilab-Tips">http://www.equalis.com/blogpost/731635/Scilab-Tips</a><br />
<br />
It's a suggestion for improving Scilab community integration because there are users of everywhere, and if you need anything about Scilab, I believe Equalis portal is the place where you can find anyone that can help you.<br />
<br />
Another useful way for using Equalis portal is to make yourself more visible in Scilab community, probably you know something that is the solution for a doubt of other Scilab user.<br />
<br /></div>Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-28033089831919550122011-11-02T15:42:00.000-03:002011-11-02T15:42:58.781-03:00The highest number<div dir="ltr" style="text-align: left;" trbidi="on">It's known Scilab works as a calculator, displaying results of math operations.<br />
<br />
I was trying to obtain the highest number that Scilab can work with, so it's what I found:<br />
<br />
-->1.<wbr></wbr>797693134862315807999999999999<wbr></wbr>9999999999999999999999999e+308<br />
ans =<br />
<br />
1.79D+308 <br />
<br />
-->1.797693134862315808e+308<br />
ans =<br />
<br />
Inf<br />
<br />
It's a great number! And I think this number can attend all our needs for computations and operations.<br />
<br />
</div>Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com1tag:blogger.com,1999:blog-9101701713138538731.post-1023962724968470152011-10-12T12:52:00.000-03:002011-10-12T12:52:28.844-03:00Simulating physical events through computer graphics techniques - rectilinear motion<div dir="ltr" style="text-align: left;" trbidi="on">Hi everyone, unfortunately my time is not being enough for making posts as I'd like to do.<br />
<br />
Let me share my situation: I'm working at morning and afternoon in a company and giving classes at night in a university.<br />
<br />
So, all days of my weeks are full of activities and studies. I wish to set my time better on the following days, because I like to make posts on my blogs and share something of what I know.<br />
<br />
In this post, I want to teach how to simulate a physical event using computer graphics techniques, just a comment: one of my disciplines in the university is computer graphics and we are using Scilab for the examples and exercises.<br />
<br />
Let's try to simulate some kinematics events, about <span class="short_text" id="result_box" lang="en"><span class="hps">rectilinear motions.</span></span><br />
<br />
<span class="short_text" id="result_box" lang="en"><span class="hps">For a first example, being a punctual object that's moving over a horizontal line (on the floor) and we wish to see this moving event by a top vision.</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps">The movement equation is</span></span><br />
<br />
<div style="text-align: center;"><span class="short_text" id="result_box" lang="en"><span class="hps"> <i>position = </i></span></span><span class="short_text" id="result_box" lang="en"><span class="hps"><i>initial_</i></span></span><span class="short_text" id="result_box" lang="en"><span class="hps"><i>position + velocity * time_variation</i></span></span></div><span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps">Now, writing the code:</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps">initial_</span></span><span class="short_text" id="result_box" lang="en"><span class="hps">position = [0; 0]; //point that refers to initial position meaning [x_initial_coordinate; y_initial_coordinate]</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps">velocity = [1; 2]; //vector velocity meaning [x_velocity_component; y_velocity_component]</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps">time = [0:10]; //instants that we will create samples for showing on the screen</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps">position = initial_position*ones(1, length(time)) + velocity*time; //this command implements the movement equation, and the matrix </span></span><span class="short_text" id="result_box" lang="en"><span class="hps">ones(1, length(time)) is used for correcting the dimensions and makes the matrices sum possible</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps">for t = 1:length(time), //this loop creates the graph dynamically simulating real motion</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps"> plot(</span></span><span class="short_text" id="result_box" lang="en"><span class="hps">position(1,[1:t]), position(2,[1:t]), '.y');</span></span> </b><br />
<b> plot(position(1,t), position(2,t), '.');</b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps"></span></span></b><b><span class="short_text" id="result_box" lang="en"><span class="hps"> sleep(1000);</span></span></b><br />
<b><span class="short_text" id="result_box" lang="en"><span class="hps">end;</span></span></b><span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps">This code will show the last point of position with blue color and the other points with yellow color.</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps">Test the code and send me feedback of your feelings.</span></span><br />
<span class="short_text" id="result_box" lang="en"><span class="hps"><br />
</span></span></div>Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com1tag:blogger.com,1999:blog-9101701713138538731.post-15922428724474156472011-02-11T21:33:00.000-03:002011-02-11T21:33:59.982-03:00Statistics operators mean and stdev<div dir="ltr" style="text-align: left;" trbidi="on">Hi everyone, it's so much time without posts, but it's a new one for you.<br />
<br />
Let's see anything about two functions very useful in statistics: <b>mean()</b> and <b>stdev()</b>.<br />
<br />
The function mean() returns the mean of a set of data, e. g. vectors, matrices, etc. and the function stdev() returns the standard deviation of a set of data.<br />
<br />
Let's try some examples now.<br />
<br />
-->x = rand(1, 3)<br />
x =<br />
<br />
0.1708866 0.9025495 0.4888218 <br />
<br />
-->mean(x)<br />
ans =<br />
<br />
0.5207526 <br />
<br />
-->stdev(x)<br />
ans =<br />
<br />
0.3668751<br />
<br />
<br />
These functions are useful mainly in data mining, for example: two sets of data are given <b>x</b> and <b>y</b> (each data point has two dimensions), and it's necessary to identify a region in the data space for each set.<br />
<br />
For starting, we create the sets of data:<br />
<br />
x = rand(50, 2) + 1; // see <a href="http://usingscilab.blogspot.com/2009/02/vectors-and-matrices-3.html">this link</a><br />
y = rand(50, 2, 'normal');<br />
<br />
For determining the regions, we use the functions <b>mean()</b> and <b>stdev()</b><br />
<br />
mean_x = mean(x, 'r');<br />
mean_y = mean(y, 'r');<br />
<br />
<b>mean_x</b> and <b>mean_y</b> are the centers of the sets of data, where each one has two components: mean_x = [x_xm x_ym] and mean_y = [y_xm y_ym] <br />
<br />
std_x = stdev(x);<br />
std_y = stdev(y);<br />
<br />
<b>std_x</b> and <b>std_y</b> are the distance from the centers to the boundaries of each region that we were looking for, or we can use a multiple of the standard deviation.<br />
<br />
In the example, the regions created were circles with center in the mean and radius <b>n</b> times standard deviation, but we could try more complexes regions, or not?<br />
<br />
</div>Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-31215669057136502212010-12-26T19:00:00.000-03:002010-12-26T19:00:30.632-03:00Merry Christmas and Happy New YearHi everyone, I'm very happy those days because I've started at my first job, I hadn't worked out of the university before.<br />
<br />
So I'm living out of my home, in another state, but now I'll restart to make posts in my blogs.<br />
<br />
I wish everyone were a merry Christmas and a blessed new year.<br />
<br />
And for my readers who have send questions, I ask you send me your questions again.<br />
<br />
Thank you for reading my blogs and let's study and learn.Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com1tag:blogger.com,1999:blog-9101701713138538731.post-85454602761036186182010-11-04T10:59:00.001-03:002010-11-04T11:00:26.716-03:00Thank you CVI read four comments from CV today, and I'd like to say thank you CV, a reader like you motivates me to stay improving this blog.<br />
<br />
About your comments, try <a href="http://atoms.scilab.org/toolboxes/Scilab_USB">this toolbox</a> for USB connections and, about car plates, I'll make some posts for it.<br />
<br />
So, I'm happy with my readers and I ask God bless everyone.<br />
<br />
Thank you again.Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com5tag:blogger.com,1999:blog-9101701713138538731.post-7154714909587466022010-10-19T16:05:00.000-03:002010-10-19T16:05:23.251-03:00Scilab consortium memberToday I was invited to take part in a community of math, science and technology based on Scilab software, it's <a href="http://www.equalis.com/">Equalis</a>.<br />
<br />
I've been very happy because I believe Scilab is a great software and this software just needs people who help it to become better.<br />
<br />
Now, I'd like to invite my readers to make an account in Equalis' site, but I ask you don't forget my blog.<br />
<br />
So, it's all. Let's improve our applications using Scilab.Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com0tag:blogger.com,1999:blog-9101701713138538731.post-6534851517159221462010-07-28T16:11:00.000-03:002010-07-28T16:11:46.694-03:00Car plate trackingI found an old project that I developed during my graduation course which consists in a car plate tracking system.<br />
<br />
It was developed in Python in 2007, but I translated it to Scilab, in some minutes, today.<br />
<br />
I used SIVp toolbox and simple pattern recognition and digital image and signal processing techniques in this system.<br />
<br />
The system is tested with a set of images from a Brazilian repository which has many images of cars.<br />
<br />
Look the result of the system.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5LJs2_e3KBLTK3p1VF4ejn6xfhYeU3eSWav010W8pN7tF_72ha86Ja5603Gj6gJLSm6UMxuEkCYRVPqbzNgXfpuMwbo0GbCKmwUVMo9h1ScTw1KAjltZucYwf8ctcvmk8koikUyCVUSd/s1600/car_plate.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5LJs2_e3KBLTK3p1VF4ejn6xfhYeU3eSWav010W8pN7tF_72ha86Ja5603Gj6gJLSm6UMxuEkCYRVPqbzNgXfpuMwbo0GbCKmwUVMo9h1ScTw1KAjltZucYwf8ctcvmk8koikUyCVUSd/s320/car_plate.png" /></a></div><br />
If anyone is interested in this system, come on let's talk about it. We can try to improve it.Alex Carneirohttp://www.blogger.com/profile/14503428177777397005noreply@blogger.com5