Wednesday, November 2, 2011

The highest number

It's known Scilab works as a calculator, displaying results of math operations.

I was trying to obtain the highest number that Scilab can work with, so it's what I found:

-->1.7976931348623158079999999999999999999999999999999999999e+308
 ans  =

    1.79D+308 

-->1.797693134862315808e+308
 ans  =

    Inf

It's a great number! And I think this number can attend all our needs for computations and operations.

Wednesday, October 12, 2011

Simulating physical events through computer graphics techniques - rectilinear motion

Hi everyone, unfortunately my time is not being enough for making posts as I'd like to do.

Let me share my situation: I'm working at morning and afternoon in a company and giving classes at night in a university.

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.

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.

Let's try to simulate some kinematics events, about rectilinear motions.

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.


The movement equation is

position = initial_position + velocity * time_variation


Now, writing the code:


initial_position = [0; 0]; //point that refers to initial position meaning [x_initial_coordinate; y_initial_coordinate]


velocity = [1; 2]; //vector velocity meaning [x_velocity_component; y_velocity_component]


time = [0:10]; //instants that we will create samples for showing on the screen


position = initial_position*ones(1, length(time)) + velocity*time; //this command implements the movement equation, and the matrix ones(1, length(time)) is used for correcting the dimensions and makes the matrices sum possible


for t = 1:length(time), //this loop creates the graph dynamically simulating real motion
 plot(position(1,[1:t]), position(2,[1:t]), '.y'); 
 plot(position(1,t), position(2,t), '.');
 sleep(1000);
end;





This code will show the last point of position with blue color and the other points with yellow color.


Test the code and send me feedback of your feelings.

Friday, February 11, 2011

Statistics operators mean and stdev

Hi everyone, it's so much time without posts, but it's a new one for you.

Let's see anything about two functions very useful in statistics: mean() and stdev().

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.

Let's try some examples now.

-->x = rand(1, 3)
 x  =

    0.1708866    0.9025495    0.4888218 

-->mean(x)
 ans  =

    0.5207526 

-->stdev(x)
 ans  =

    0.3668751


These functions are useful mainly in data mining, for example: two sets of data are given x and y (each data point has two dimensions), and it's necessary to identify a region in the data space for each set.

For starting, we create the sets of data:

x = rand(50, 2) + 1; // see this link
y = rand(50, 2, 'normal');

For determining the regions, we use the functions mean() and stdev()

mean_x = mean(x, 'r');
mean_y = mean(y, 'r');

mean_x and mean_y 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]

std_x = stdev(x);
std_y = stdev(y);

std_x and std_y 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.

In the example, the regions created were circles with center in the mean and radius n times standard deviation, but we could try more complexes regions, or not?