<<

Quick Ref-Card

Basic operators Extracting elements, rows & columns Standard functions

+ addition for scalers, vectors, matrices etc. X(n) nth element of vector X Trigonometric functions - subtraction for scalers, vectors, matrices etc. X($) last element of vector X 7 Accepts input in radians. For degrees use sind(45) \ 2\7 = 3.5 i.e. 2 divides 7 X($-1) second last element of vector X 2 sin sin / 2/7 = 0.2857143 i.e. fraction 2 A(2,3) element of matrix A at 2nd row, 3rd column 7 cos cos * multiplication of scaler, matrices A(:,2) In matrix A second column, :all rows tan tan ^ 2^3 computes 23 A(n,:) nth row and all entries in nth row sec sec // comment line A(:,$) Last column of matrix A csc cosec : Defines range 1:5 will print A($-1,:) Second last row cotg cot sequence of as 1. 2. 3. 4. 5. A(2:3,1:2) submatrix i.e. entries from 2nd to 3rd row asin sin inverse with default increment as 1 and 1st to 2nd column of matrix A acos cos inverse ; to suppress output atan tan inverse asec sec inverse Data types / objects Advanced operations acsc cosec inverse acot cot inverse .* element wise multiplication, applicable to scaler x=3 Assigns value to variable x which vectors, matrices Mathematical functions becomes scaler. ./ U, V are vectors(or matrices), U./V is range 2 : .5 : 4 will print sequence of numbers u ./v , ··· , u ./v , exp exponential starting from 2 with of increment .5 1 1 k k u1 uk log logarithm in the range 2 to 4. in other words , ··· , v1 vk round linspace e.g. linspace(2,3,11) will .\ U, V are vectors, U.\V is floor earlier highest integer return sequence of equally space points v1.\u1, ··· , vk.\uk, ceil next lowest integer v v in the interval [2, 3] in other words 1 , ··· , k int only integer part u1 uk vector U=[2,9,-4] −1 modulo(x,y) x (mod y) gives remainder U becomes the vector of length 3 A\B Matrix A divides matrix B i.e. A × B   factorial(n) will out put n! 3 4 factors(a) will factor a in prime numbers matrix A=[3,4;5,11] A = A/B Matrix B divides matrix A i.e. A × B−1 5 11 sqrt(5) square root of a number ; separates rows. abs(-5) absolute value of a number n! returns n factorial complex 3+%i This will dislay complex number 3 + i ; 2/3; will supress output number Miscellaneous functions variable x x = poly(0,0 x0) This will declare x as a variable x which is soln clear a delete the predefined object a of polynomialx = 0. Logical operators disp(x) Prints value of x disp(‘‘abc’’) Prints string as it is find find(A<3) will return index value Predefined constants Logical operations returns answers as TRUE or FALSE a < b is a strictly less than b? (positions of values) in A which are < 3 0 > d is d less than 0? clean(x) will round x to 0 %pi π with numerical value assigned m <= n is m is less than or equal to n? format(’v’,20) set number of digits to 20 %e e base in natural√ logarithm e = 2.7182818 a >= 0 is a great than on equal to 0? format(’e’,20) represent number in scientific format %i complex number −1 A <> B is A not equal to B e.g. 2345=2.345D+03 which is equivalent to 3 %inf Infinity a == b is a equals to b? 2.345 × 10 %eps machine epsilon help("plot") display help for plot command Matrix related functions Special Matrices Graphics eye(3,3) Identity matrix of size 3 × 3 plot(sin(x)) ones(3,3) Matrix of size 3 × 3 with plot sin graph Vs index value If A is some matrix already defined. each element= ’1’. plot(x,y) graph ofx Vs y length(A) It will return number of elements in A. zeros(1,2) Matrix of size 1 × 2 with plot(x,y,x,w) size(A) return number of rows, columns in A each element = ’0’. plot2d sum(A) Addition of all elements of A rand(2,3) Matrix of size 2 × 3 with entries fplot2d 2-d function plot prod(A) Product of all elements generated randomly between 0 and 1 fplot3d 3-d function plot ’ transpose of matrix, e.g. A’, " 2 0 0 # fplot3d1 colourful 3D graph where A is a matrix diag([2 -5 7]) will output matrix as 0 −5 0 subplot() divide plot windows trace(A) Addition of all diagonal elements 0 0 7 xlabel() horizontal label to graph diag(A) Extract all diagonal elements ylabel() vertical label max(A) maximum element in matrix A Programming legend() list of graphs with colours used min(A) minimum element in matrix A Inline function defination clf() close graphics window rank(A) rank of matrix A deff (’y=funname(x)’,’y=2*sin(x)’) pie() pie graph det(A) It will find the determinant y is temporary variable. contour contour plot of the square matrix. funname is name of the function. champ vector field plot inv(A) if determinant is non singular (i.e. 6= 0) y=2*sin(x) is function definition champ1 then it will compute the inverse For loop Advanced Matrix related functions of the matrix rref Row reduced echelon form returns identity spectrum- it will compute eigen values spec(A) k=0 matrix and diagonal matrix will assign eigen values to E [V,E]=spec(A) for i=1:n [AB] Augmented matrix is possible by writing in diagonal matrix form will assign k=3*i+1 one matrix followed by the other one corresponding eigen vectors in column end svd returns singular value decomposition form to matrix V LU LU decomposition returns upper triangular, if (condn) then ...end lower triangular, upper triangular, if (condn) then...else...end & Identity matrix or pivoted matrix while(codn)...end bdiag block matrix Polynomial operations function[output]=funname(input) Points to be noted output=calculation endfunction • function returns more than one value. x=poly(0,’x’) declare x as poly with function[f]=fibbo(n) • append operation is possible with a = [a, 2]. variable x and root= 0 f=[ 1 1] • Matrix in one variable (defined by poly x=poly(v,’x’,’coef’) declare poly with variable x temp=0 command). & coefficients from vector v for i=2:n • works in same way. Operations for matrix roots(f) will find roots of polynomial f. temp=f($) +f($-1) works with it. polfact(f) will factorize polynomial f. f=[f temp] derivat(f) derivative of polynomial f end • matrix, polynomial are also valid inputs horner(f,5) evaluate poly f at 5. endfunction for functions. coeff(f) returns coefficient of the poly f. continue: continues with next • Scilab acts on whole vector at a time, use degree(f) returns degree of poly f counter value, skip the current counter of loops can be avoided.

Manjusha Joshi email:[email protected] August 13, 2014