Tuesday, July 8, 2014

Freemat Plotting

Freemat plotting is very easy. Its just like plot(x,y) and it will plot it .
There are some attribute you can add to this plot
like
1. Plot it like line or scatter plot

Line Plot
--------------------------------------------------------------------------------------------------
plot(x,y)

Scatter Plot
---------------------------------------------------------------------------------------------------
plot (x,y,'*')

You can use most of the symbol for representation of the points in the plot.

2.Set min max of the axis

axis ([xmin xmax ymin ymax])

so give the values in that order inside the [] and then within ()

3. Reverse axis

set(gca,'XDir','reverse') or the YDir

4. Colour

For colour just write the code like
plot(x,y,'g')

'g' - represent green.

Few short forms are

  • 'b' - Color Blue
  • 'g' - Color Green
  • 'r' - Color Red
  • 'c' - Color Cyan
  • 'm' - Color Magenta
  • 'y' - Color Yellow
  • 'k' - Color Black
The symbolspec specifies the (optional) symbol to be drawn at each data point:
  • '.' - Dot symbol
  • 'o' - Circle symbol
  • 'x' - Times symbol
  • '+' - Plus symbol
  • '*' - Asterisk symbol
  • 's' - Square symbol
  • 'd' - Diamond symbol
  • 'v' - Downward-pointing triangle symbol
  • '^' - Upward-pointing triangle symbol
  • '<' - Left-pointing triangle symbol
  • '>' - Right-pointing triangle symbol
The linestylespec specifies the (optional) line style to use for each data series:
  • '-' - Solid line style
  • ':' - Dotted line style
  • '-.' - Dot-Dash-Dot-Dash line style
  • '--' - Dashed line style



Saturday, April 12, 2014

How to create a Matrix Using Freemat

By now we have come to know some basics about Matrix. Now how to create them and later work with them. Its very easy to create matrix in Freemat.
The commands are similar to Matlab.

1. Row Matrix
---------------------------------------------------------------------------------------------------------------------
A = [ 1 2 3 4 ]

A is the name of the matrix and the value of all the elements are stored in the variable A. You can name it anything .Its an array and give a location number to all the elements of the matrix. The picture of freemat is given below.

If we are defining Matrix we have to use square brackets and inside the brackets we have to write the elements. In creating row matrix we just separate the element with blank spaces only.

2. Column Matrix
---------------------------------------------------------------------------------------------------------------------
B = [ 1; 2; 3; 4 ]

We assigned another name to a column matrix.  Here each element is separated by a ';' . Square bracket is need and every element is given an address to identify it.
Like what does
B(2,1) signify
Its the 'B' Matrix
2nd Row
1st Column
So B(2,1) is 2
The pic is given Below.

3. Any size Matrix
---------------------------------------------------------------------------------------------------------------------
C = [1 2 3 4;5 6 7 8;9 10 11 12]

Here we have created 3 row matrices and a ';' in between them to make the program understand that next segment belong to the next row. So we have 3 row staked together making it a 3X3 matrix.

4. Random Number matrix
---------------------------------------------------------------------------------------------------------------------
D = rand(3,3)

'rand' is the command for random matrix. After a command you don't need to use the square brackets but use first brackets ( ) . This contain the specifications for 'rand' command i.e a 3X3 matrix. The first element signify the number of rows and the second signify the number of columns.




5. Null matrix or Zero Matrix
---------------------------------------------------------------------------------------------------------------------

A = zeros(3,3)

will produce all the 9 elements as zero which is also called null matrix

6. Identity Matrix
---------------------------------------------------------------------------------------------------------------------
B   = eye(3)

Identity matrix is a square matrix of all zeros except the diagonal. The diagonal is one.

7. All One Matrix
-------------------------------------------------------------------------------------------------------------------

C = ones(3,3)

Creates all the elements as one




Thursday, April 10, 2014

Freemat Matrix Operations

Being an oil industry guy and the interest of using Freemat is mainly for using seismic, logs and related application i will mainly concentrate on these and some basic mathematical operations.

Matrix Addition. 
--------------------------------------------------------------------------------------------------

Source - mathsisfun.com

In order to add two matrices the size of matrix has to be same . Whats size? click here
If 
A is (5X2) and B is (5X2 ) then they can be added or else not possible.
You can individually add each element of the same location like the image.
Location of '3' of first matrix is (1,1) and
Location of '4' of second matix is (1,1) 

so they can be added (3+4) = 7 for the same location (1,1)


Matrix subtraction.
--------------------------------------------------------------------------------------------------------------


Source :- mathsisfun.com

The theory is same as the addition but here we are just subtracting. 


Matrix Multiplication
------------------------------------------------------------------------------------------------------------------

1. Scalar Multiplication

Multiply a matrix by a constant value is a scalar multiplication. Like

Source :- mathplanet.com


2. Vector Multiplication



This is an operation where we don't require a similar size of matrix but we need to check the number of columns of first matrix and number of rows of second matrix.
If they match then we can multiply two Matrix.
Result = Column * Row
The multiplication is shown in the above pic.

Matrix Division
----------------------------------------------------------------------------------------------------------------------------------
1. Scalar Division

This means you can divide a matrix by a scalar like

A= | 4 8 10|
      |6 4  12|

A/2= |4/2 8/2 10/2|
         |6/2 4/2 12/2|

So that is easy but what about dividing a matrix by another matrix
That part is a little tricky
Direct Matrix Division is not possible where you divide each element by another 
So if

A= | 4 8 10|                                    B= | 1 2 3 |
      |6 4  12|                                          | 5 8 9 |

then A/B = tricky
A/B can be done by A*B(Inverse)
Just like in real number 10/2 = 10*2(inverse)
           2 inverse is 1/2 = 0.5

But finding  the inverse of a matrix is not so easy .
But in Freemat you can do it easily 
Points to remember is that 
a. Only Square Matrix have Inverse 
b. Not all square matrix have inverse . Those who dont have inverse are called Singular.



Wednesday, April 2, 2014

Freemat See Things in Matrix

Freemat provides a matrix environment of numerical analysis. Freemat sees things like its a matrix, so have to know a little about matrix if you are really interested in using Freemat.

  | 1 2 3 4|
  | 4 5 6 7|       This is a matrix.

Matrix elements should be inside a third brackets like [ 1 2 3]  but here let it make simple for writing here and i will write it like | 1 2 3|

Now 1,2, 3     are elements of the matrix and every element have a address to recognize the element . Just like out home address relates to the person who lives in the address. So we can know every element if someone give us the address of the element.

so this address of the elements of the matrix is given by two term
1)  Row
2) Column

what is row ?

The horizontal line of the matrix is called row.

A=    |1 2 3 |    --------------------Row 1
        |4 5 6 |    --------------------Row 2

What is Column ?
The vertical line is called column.


A=     | 1 2 3 |                                A=  | 1 2 3 |
         | 4 5 6 |                                      | 4 5 6 |
            ^                                                   ^
      Column 1                                     Column 2

Columns are perpendicular to rows

So how many rows and Columns does this matrix have ?

B =     | 1 2 3 4 |
          | 5 6 7 8 |

So B matrix have 2 Rows and 4 Columns

So whats the Size of B
                 = 2 4.

Sunday, March 23, 2014

Download Freemat

Hi friends,
Now that i have decided to use freemat i need to get the programing Language. You can download the latest version of freemat from HERE. Here you will finds windows for different platform. I use windows and so downloaded Freemat 4.0 for my PC.
This gives an .EXE file so just double click it and the software will be installed. Go to start button and you will find Freemat in 'All Programs'.

Run it by clicking it.

It will look like


Thursday, March 20, 2014

The Beginning

HI Friends ....
I am new to this coding world and is in a process of creating something wonderful with my efforts. I needed a platform to test my code and here comes the toughest questing- what to select? Matlab was the best that i came across but being a student i couldn't afford it although Matlab have a cheap version for students. I am always a believer of open source so thought whats the best possible alternative to Matlab and i got so many, among which GnuOctave and Freemat stood a good chance . Freemat is not as mature as octave but somehow i got attracted towards Freemat.

Freemat doesn't have excellent user support and the web presence is also very low so i thought let me help a little from my side to this wonderful creation.I am learning this software and will keep on posting what ever i feel new to me and feel like sharing. I am not good in English too so bear with me if you are following me.

I would love to have your comments and my blogs and approaches may not be correct so please comment and correct me . Thanks you all.