INTERNET MATLAB

The Internet Matlab iMatLab is an internet version of matrix calculations language. Site artspb.com keeps e-books with interpreted formulaes. iMatLab allows to write mathematical notes, to make lessons, and to create internet toolboxes. Besides matrix calculations iMatlab supports a language of pictures management. There is a version of iMatLab adapted to Opera Mini/Mobile: Matlab mobile.

THE BASIC DIFFERENCES

List three basic differences of Internet MatLab with non Internet versions.

First of all, axis of time t (the name is fixed) it is generated by special function t=time(interval), instead of t=0:step:interval. Other functions of time t are introdused by predicate fun: x=fun(sin(t)), y=fun(cos(2*t)), etc.

Second is all matrix and vector binar operations have a predicate: A={B+C}, C={A*B}, D={A\B}, just A={B}. Note A = {B+C} is an error (blanks inside). More complicated expressions have twine brackets: A={{B*C+D}}.

Third is operations are separated by commas, therefore arguments of subroutines are separated by blanks.


EXCEPTIONS

Less essential that Internet MatLab inherits properties of Internet languages, in particular, properties of Javascript.

There is no concept of usual and trasposed vectors here. These vectors are non-distinct. Numeration of vector components it begins with zero: x[0] is a first element. The reference to element of a matrix it looks like A[j][i], i.e. consists index j of a COLUMN at the first place.

DIMENSIONS of VECTORS and MATRICES

n=rows(A) returns quantity of rows (lines), m=cols(A) returns quantity of columns. For cycles its more handy to use n=rowm(A) returns number of the latest row (line), m=colm(A) returns number of the latest column. So rowm(A)=rows(A)-1, colm(A)=cols(A)-1. The numbering of vector components it begins with zero, function n=size(X) returns number of the latest component of a vector.

Following the syntax, distributed in Internet, the index of an element consists in square brackets X[i]. By the same rule A[0] consists an initial column A(:,1), A[1] - second column A(:,2), etc., then A[0][1] is an element A(1,0) (i.e. number of column it is at the first place).

Part of j-columns it returns x=block(A[j] i1 i2). Part of matrix returns B=blocks(A i1 i2 j1 j2).

SOME EXAMPLES

The typical matrix assignment looks A=[-1 -3; 3 -2], b=[1 1], c=[1 1].

The lines of a matrix are separated by a point with comma A=[1 2; 3 4], to solve system of linear algebraic equations AX=b it’s enough to write X={A\b}. The left and right operations of division A\B and A/B differ by in the first case the matrix A is inverted, and in the second one B is inverted already.

Transposition looks like tr(A), diagonal sampling it is diag(A), in both these cases A keeps the result. Column normalization norms(A) has the same property. Operation diags(A) allocates eigen values, real and imaginary parts of eigen values are stored in two columns vector.

% it is a sign of a comment

DATA, FUNCTION and EIGEN VALUES plotters

To see content of matrix write A=?, it looks like graph by y=?? (matrix output is supported by matrix plotter). Well is also plot([t y1 y1.. so on]).

For example: t=time(1), y=fun(sin(t)+3), [t y]=??, two functions t=time (2*PI), x=fun(sin(t)), y=fun(cos(2*t)), plot(t [x y]) or plot(x y).

Eigen values on a complex plane, it looks like D=eig(A), diags(D), plots(D).

Matrix plotter it looks like mesh(A), for example: A=rands(4), mesh(abs(A)).

BAR-plotter: A=[1 2; 3 4], bar(A), bar(A:3D) (options: 2D, 3D, 3T (temporal), M (mesh), C (color), @), XML-data plotted by bar('A':M), receivebar('A') and so on.

SOME CONSTANTS

The numbers PI, E, also root with 2 it is SQRT2, logarithms are entered: LN2=ln2, LN10=ln10.

GENERATORS of VECTORS and MATRICES

Axis of time and the integers are generated by functions t=time(T n), where n is quantity of points, and x=line(n). Example: x=line(3) generates a vector with three components x=[0 1 2].

Vector with units 1 generated by x=one(n), zero vector is x=zero(n), vector of random numbers is x=rand(n) with amplitudes no more than 1. The square matrixes are generated by similar functions A=ones(n), B=zeros(n), R=rands(n). Besides a diagonal matrix (whole zero with 1-diagonal) it is I=eye(n).

If it is necessary to generate a vector or matrix of the same size, as a sample, the sample is used as an argument, for example: I=eye(A).

Generators create initial arrays: x=time(1), y=zero(x), for i=0:size(x), y[i]=sin(x[i]+3), end.

SCALAR FUNCTIONS, FUNCTIONS of VECTOR and MATRIX ARGUMENTS

The functions of scalar argument do not require predicate y=exp(x), y=log(x), y=sin(x), y=cos(x), y=tan(x), y=asin(x), y=acos(x), y=atan(x), y=sqrt(x), y=round(x), y=floor(x). You can write mathematical formula with them.

Time is t=time(interval). An additional option allows to specify quantity of points: t=time(T 200), by default it is 100 points. The functions of the time are entered by predicate fun: y=fun(sin(t)+2*cos(t)).

Polinomial calculations: v=polyv(N p), where point p=[re im], result is an complex number with magnitude a=norm(v)).

Scalar functions of matrix and vector arguments are entered by {}: A={abs(B)},

F={floor(A)}, etc. The same is for formulas: matrix addition, subtraction, multiplication and division are entered by predicate calc and the insertions are not analyzed (too, with the purposes of acceleration of calculations).

For trigonometrical functions it is authorized to use a sign of argument or scalar multipliers: T=times(10), Y={sin(T)}, Y={exp(-T)}, Y={exp(2*T)} and so on.

MATRIX CALCULATIONS

The solution of linear equations Ax=b looks like A=[1 2; 3 4], b=[1 1], x={A\b}. This rule concerns everything that is connected with matrices, including equating B={A}. Recursive building is A={[A c]}, make column A=join(B C). Note A=B means A and B are the same matix (!), changing B we change A.

The left and right operation of division A\B and A/B differ by in the first case the matrix A is inverted, and in the second one B is inverted already. It is possible also point-by-point operations: C={A.*B} and C={A./B}. To operate with a scalar: B={2*A}, B={A/2}, B={2+A} and so on. However inversion uses own function B=inv(A).

Functions to search a minimum and maximum are m=min(A), M=max(A), by absolute meanings it looks like m=min(abs(A)), M=max(abs(A)). The same way it’s calculated matrix of saturations C=sat(A M), where M sets possible absolute meaning, and there is also n=norm(A).

There are a summation and product of vector elements s=sum(X), p=mul(X), reversed vector is y=flip(X).

Scalar product it looks like s={x'*y}. The same with transposed matrix: S={A'*B}. Hyperbola is calculated by y={1/x}. There are two resolvents: R=res(A-d*I), where d is a number (I observed as eye(A)), Q=res(A+b*c), where b is vector, c is row (line).

Single operations: transposition tr(A), diagonal allocation diag(A), triangle allocations tril(A) è triu(A), column normalization norms(A). A keeps the result. Eigen values taken with a three-diagonal matrix diags(A) they result in two-columns vector consisting its real and imaginary parts.

CYCLES

Example of a cycle: S=0, for i=0:100, S=S+1, end, S=?, reversed (with step -1 only): S=0, for i=5:-1:1, S=S+1, end, S=?. A cycle due dimension of a vector: S=0, for i=0:size(X), S=S+X[i], end, S=?.

A cycle with a condition: S=0, while S<10, S=S+1, end, S=?.

IF-logic (OPERATION of COMPARISON = == > < < = > = ~ =)

if A>B, A=?, else, B=?, end,

Logic "and" is entered by an usual symbol A>B&A>C, logic "or" is similar: A>B|A>C (for both cases equality is strongly ==, i.e. A==B&A==C or A==B|A==C).

DYNAMIC SYSTEMS SIMULATION

Let be a state space model dx/dt=Ax+bu, y=cx given by matrix S=[A b; c 0] determined as a system the following way S=ss(A b c). In the latest case it could be reversed to initial matices such way: A=S[0], b=S[1], c=S[2].

The response calculated through function lsim (linear system simulation): y=lsim(S u(t)) (control toolbox has much more functions).

For example: A=[-1 -3; 3 -2], b=[1 1], c=[1 1], S=ss(A b c), t=time(5), u=one(t), y=lsim(S u(t)), [t y] =??.

You can use also parameters of transfer function, specified by coefficients of numerator and denominator: N=[1 0], D=[0.01 0.1 0], t=time(1), u=one(t), y=lsim(N D u(t)), [t y]=??.

There is toolbox to calculate impulse and step responses, matrices of observability and controlability, canonical form of dynamic system, etc.

TOOLBOXES

iMatlab keeps and allows to write internet toolboxes. There is control toolbox and other toolboxes (lsm-toolbox, for identification, etc.) swithed by %toolbox control to internet books or student-forums.

It allows to calculate step response call y=step(N D t), impulse response call y=impulse(N D t), matrix of system call S=tf(N D), get F=compan(N), line of frequence w=frequence(W), then call a=bode(N D w), and etc (toolbox functions with 2 and more arguments are called by call).

call y=lsims(N D x u t) uses vector x of initial state of line of integrators.


THE SOLUTION of SYSTEM of LINEAR EQUATIONS

To solve system of linear equations: A=[1 2; 2 1], b=[1 1], x={A\b}, x=?.

Inversion and pseudo-inversion of matrix is I=inv(A), calculation of its rank is r=rank(A), the product b={A*x}, calculation of angle sines of column vectors (in relation to linear shells constructed with them): S=conds(A), matrix condition is product condS=mul(S), it gives 1 if columns are orthogonal and 0 if they are linear dependent on each-other.

The pseudo-inversion A=inv(B) coincides with inverted matrix A, in common, singular matrices leads to a minimal solution: ||AB-I||->min, ||A||->min. Level of tolerance to calculate rank of matrix can be changed, default meaning is tolerance=0.0000001.

MATRIX TRIANGULATIONS

The Cholecky decomposition L=chol(A) (of the symmetric positive matrix A) finds triangular multipliers A=L*L'.

A=QR decomposition with orthogonal Q and right top triangular R matrix multipliers it's given by functions: Q=Qr(A), R=qR(A), R=qr(A), [Q R]=qr(A).

THE SCHOOL FORMULAS

The determinant of a matrix, in general, is searched through product of its eigen values, but for matrices not higher than in the fourth strings there is a function calculating the determinant by the school formulas, well known

in matrix algebra: if size(A)<4, d=det(A), end.

EIGEN VALUES of MATRICES

D=eig (A) returns real form of Jordan matrix (each complex eigen value a+jb is submitted by block [a b;-b a], eigen vectors matrix V contains real and imaginary components of complex eigen vectors, such way [V D]=eig(A) or V=eigv(A) returns parts of eigen decomposition A=VD/V.

Output of eigen values to a complex plane looks like D=eig(A), diags(D), plots(D).

Resolvents calculation: d=1, R=res(A-d*I), Q=res(A+b*c) where b and c it is a vector and a line.

USER FUNCTIONS

The subroutines are entered by predicate 'function', example is: function: SET, A=2, end, and to call it write: call SET (the name of function follows).

You can describe local variables by var a b c (as definition and briefly in a cycle: for var i=0:size (x), ... , end), 'return' specifies the result of function.

call S=SUM(1 2), function: SUM(X Y), S=X+Y, return S, end.

Operator call it's necessary only if you have more then one argument separated by blanks.

SINGULAR DECOMPOSITION of MATRIX (TOOLBOX)

Let's write toolbox devoted to two procedures of singular decomposition A=USV'.

function: SVD(A),
var U V S, S={A'*A}, [V S]=eig(S), S={abs(S)}, S={sqrt(S)},
U={A*V}, U={U/S}, norms(U), norms(V),
return S, end,

function: SVD2(A),
var S, for var i=1:20, S=qr(A), tr(S), end,
diag(S), S={abs(S)},
return S, end,

THE TIMER

call ticker(interval) restarts the program through interval given in milliseconds. It allows make real time control systems. There is timer counter called as tick (it can be analyzed by IF).

The timer restarts the program once only, therefore it can be stopped by script (not start after n ticks). The simpliest way to renew the counter is the program should be reloaded through browser.

COMPUTER ANIMATION (VISUALIZATION)

The elementary animation functions of Visual Matlab are realized. Animation and diagram drawing occur at the end of calculation, the step of timer is given through timer(10) by default, i.e. it is possible to change this parameter (it's milliseconds).

The simulated object can be taken with library of graphic images (gif pictures), for example: open subject airplane.

Further it is placed on the screen by the direct instruction: airplane moves at [X Y], and if the object is named earlier, it can be called as it/he/she.

Horizontal and vertical position of object varies by options, for example: it moves at 100 horizontal or vertical (line). Instead of absolute coordinates it is possible to use displacement with an earlier occupied position to the right, to the left, and so on: it moves 10 (points) right/left/up/down.

Command 'Show' it generates image.

VECTOR PICTURES

Vector pictures are effective to display a pendula, devices and other instrumental systems. Descriptor call R=iniFG(angle 'color' X Y) creates a picture with intial angle, '#rrggbb'-color and center coordinates.

Segment described by call addFG(R 'ToMove' 'ToTurn' 'color' X Y), where R is the picture, the next two it is mobility (T/F), ability to turn (T/F) or a text string or a name of picture img/name.gif. Then color and coordinates of polygon. Gif/jpg picture described additionally with width and height by X=[x w], Y=[y h]. Corrected by call newFG(R 'old name' 'new name' w h).

Movement by call moveX(R step), call moveY(R step), call turn(R step), positioning it looks like call moveXat(R X), call moveYat(R Y), turnat(R angle). Show it by call show(R), if it is required to move several pictures, the command is decomposed to stages call drawBG(R) – only background, next picture call drawFG(R) and conclusion for all pictures: call showFG().

In difference to pixel animation (shown finally) the vector one follows the calculations immediately.

JAVASCRIPT SERVICE

Internet Matlab allows to use javascript service, sorting looks as A=[2 -1 1], A.sort(), sorting of elements according their indexes: A=[1 3 2; a c b], A.sort().

The most popular commands: A.length, typeof(A), A.reverse(), A.pop(), A.shift(), A.unshift(a), A.push(a) it is A[A.length]=a (addition of an element).

ActiveX and Ajax of technologies used: exe-program start realized as F='file.exe', F=run('parameters'), write and read file of the client machine with the purpose to establish a communication with data units (sources): F='data.txt', F=write(A), A=read(F).

The similar operations are used to exchange server data. However to activate server service you have got password from webmaster of artspb.com. It’s a way to build Internet real time control systems.

It’s useful to begin with tutorial examples loaded by menu (Internet browser interprets errors of compiled program only). After registration each user can save own example or examples described as functions.

iMatlab (C) 2009-2000 artspb.com


© 2012 artspb.com