Tuesday, June 23, 2009

Plot 3D - surface

Ok, the world is learning how to use Scilab. I like it a lot!

Now, let's make surfaces using the function plot3d(.).

This function is called like this: plot3d(x, y, z);

Where x and y are vectors and z is a matrix.

Look the example:


-->d = -3:3;

-->[x y] = meshgrid(d)
y =

- 3. - 3. - 3. - 3. - 3. - 3. - 3.
- 2. - 2. - 2. - 2. - 2. - 2. - 2.
- 1. - 1. - 1. - 1. - 1. - 1. - 1.
0. 0. 0. 0. 0. 0. 0.
1. 1. 1. 1. 1. 1. 1.
2. 2. 2. 2. 2. 2. 2.
3. 3. 3. 3. 3. 3. 3.
x =

- 3. - 2. - 1. 0. 1. 2. 3.
- 3. - 2. - 1. 0. 1. 2. 3.
- 3. - 2. - 1. 0. 1. 2. 3.
- 3. - 2. - 1. 0. 1. 2. 3.
- 3. - 2. - 1. 0. 1. 2. 3.
- 3. - 2. - 1. 0. 1. 2. 3.
- 3. - 2. - 1. 0. 1. 2. 3.

-->z = 9 - (x.^2 + y.^2);

-->plot3d(d, d, z);


The result is showed:


The coordinates x and y were the vector d (-3:3).

We can make any surface, so let's think in other surface. Look the next example:

-->x = -5:0.1:5;

-->y = 0:0.1:10;

-->[xc yc] = meshgrid(x, y);

-->w = %pi/4;

-->b = -0.5;

-->z = exp(b*yc).*sin(w*xc);

-->plot3d(x, y, z);


The result:


Try to make tests and generate surfaces.

Friday, June 12, 2009

Plotting vectors like an animation

The last post received a comment, so I thought the readers could like to see anything more about how to plot vectors.

Let's use the Scilab's text editor, click the 'Editor' button and write the scripts, look the images.

Opening the editor.


Using the editor.

Read the buttons for use the editor's resources.

Now, let's see what happens when the following script is executed:

r = 0.1:0.1:10;

w = %pi/10;

x_i = 0;
y_i = 0;
for t = 1:length(r),
x_f = r(t)*cos(w*t);
y_f = r(t)*sin(w*t);

champ(x_i, y_i, x_f - x_i, y_f - y_i, 0.1);

x_i = x_f;
y_i = y_f;

sleep(100);
end;

--------------
The result:

Friday, June 5, 2009

Plotting vectors

I received an e-mail from a reader, I feel happy with it, so if anyone needs help, I'm receiving asks.

So, let's follow with our Scilab's tutorial.

This post is about plotting vectors, like the picture.


This kind of plotting is very common for applications on electromagnetism or analysis of fluids.

In Scilab, we can use the champ(.) function for plotting vectors.

Look the following script:

-->x = -5:5;

-->y = 0:4;

-->[xv yv] = meshgrid(x, y)
yv =

0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.
3. 3. 3. 3. 3. 3. 3. 3. 3. 3. 3.
4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4.
xv =

- 5. - 4. - 3. - 2. - 1. 0. 1. 2. 3. 4. 5.
- 5. - 4. - 3. - 2. - 1. 0. 1. 2. 3. 4. 5.
- 5. - 4. - 3. - 2. - 1. 0. 1. 2. 3. 4. 5.
- 5. - 4. - 3. - 2. - 1. 0. 1. 2. 3. 4. 5.
- 5. - 4. - 3. - 2. - 1. 0. 1. 2. 3. 4. 5.

-->wx = %pi/3;

-->xv = cos(wx*xv);

-->yv = yv/max(yv);

-->champ(x, y, xv', yv', 1);



The result is showed following:


The champ(.) has five arguments, the first and the second are the coordinates of each vector, the third and the fourth are the components of each vector, and the fifth is a correction argument (for normalization).

Try to make graphs and say me what happens.