W03 D01 LAB Computadftional Methods
W03 D01 LAB Computadftional Methods
http://freemat.sourceforge.net/
FreeMat is a free environment for rapid engineering and scientific prototyping and data processing. It is similar to commercial systems such as MATLAB from Mathworks, and IDL from Research Systems, but is Open Source. FreeMat is available under the GPL license.
Variables in FreeMat
'cell' for cell-arrays 'struct' for structure-arrays 'logical' for logical arrays 'uint8' for unsigned 8-bit integers 'int8' for signed 8-bit integers 'uint16' for unsigned 16-bit integers 'int16' for signed 16-bit integers 'uint32' for unsigned 32-bit integers 'int32' for signed 32-bit integers 'uint64' for unsigned 64-bit integers 'int64' for signed 64-bit integers 'float' for 32-bit floating point numbers 'single' is a synonym for 'float' 'double' for 64-bit floating point numbers 'char' for string arrays
Example:
A = int8(1) -> A = 1 A = int8(-1) -> A = -11 A = uint8(1) -> A = 1 A = uint8(-1) -> A = 0 B = thisisastring
y = cast(x, toclass)
'cell' for cell-arrays 'struct' for structure-arrays 'logical' for logical arrays 'uint8' for unsigned 8-bit integers 'int8' for signed 8-bit integers 'uint16' for unsigned 16-bit integers 'int16' for signed 16-bit integers 'uint32' for unsigned 32-bit integers 'int32' for signed 32-bit integers 'uint64' for unsigned 64-bit integers 'int64' for signed 64-bit integers 'float' for 32-bit floating point numbers 'single' is a synonym for 'float' 'double' for 64-bit floating point numbers 'char' for string arrays
Matrices in FreeMat
Matrices (Syntax)
variable = *row1; row2; row3; ; rowN] where each row contains the [column ]elements row1 = col1, col2, col3, , colN Example: Y = [1,2 ,3; 4, 5, 6] Ans = 1 2 3 4 5 6 There are also predefined like the following: zeros(N) diag(1:N) ones(N) rand(N)
Scripts in FreeMat
Sequence of commands contained in a .m file
Sample: test.m A = 3; printf(value of a is %f, A);
The output in the terminal will be, if executed: -> test value of a is 3 In running scripts, just type the name of the file in the console, Just like in the example, [ test ] WARNING: in your freemat console, current directory should be where the file is. Otherwise it will not run or detect the script.
Modes of operation:
a is a scalar, b is an n-dimensional array - the output is then the same size as b, and contains the result of comparing each element in b to the scalar a. a is an n-dimensional array, b is a scalar - the output is the same size as a, and contains the result of comparing each element in a to the scalar b. a and b are both n-dimensional arrays of the same size - the output is then the same size as both a and b, and contains the result of an element-wise comparison between a and b.
(for scalars& SquareMatrices only) (element-wise division) (element-wise division) (element-wise power) (element-wise multiplication) (apostrophe), conjugating transpose (simple transpose) (inverse a matrix)
In this way, freemat will try to execute first the statements_1 and if there will be errors, the statements inside the catch will be executed
FreeMat Functions
Some built-in functions clc clears the screen/console clear all clears used/declared variables,functions clock current date and time y = clock %this will create an output y = [year month day hour minute seconds] y(0) = 2013 etime elapsed time, same as clock format tic starts the stopwatch timer toc stops the stopwatch timer