Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest...

254
[100] 300 Reference, Tutorial by www.msharpmath.com [100] 300 revised on 2013.01.04 cemmath The Simple is the Best Alphabetic Listing of Cross Reference Tags "A." means a "matrix data" "W." means a "matrix data", and is writable "p." means a "poly data" (polynomial) "x." means a "double data" "z." means a "complex data" "v." means a "vertex data" "cs." means a "csys data" For example, the following syntax matrix A.inv is interpreted as A matrix "A" calls a function "inv" to find an inverse, and returns the result as a "matrix". //--------------------------------------------------------------- ------- To go to the end of file, click end of file Click characters below for a quick move. . A . . B . . C . . D . . E . . F . . G . . H . . I . . J . . K . . L . . M . . N . . O . . P . . Q . . R . . S . . T . . U . . V . . W . . X . . Y . . Z . //--------------------------------------------------------------- ------- Green-colored name-tag with no link are units and constants Blue-colored name-tag has linked contents. Click it for a quick move. Below is an example. 1

Transcript of Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest...

Page 1: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[100] 300 revised on 2013.01.04 cemmath

The Simple is the Best

Alphabetic Listing of Cross Reference Tags

"A." means a "matrix data" "W." means a "matrix data", and is writable"p." means a "poly data" (polynomial) "x." means a "double data""z." means a "complex data""v." means a "vertex data""cs." means a "csys data"

For example, the following syntax matrix A.invis interpreted as A matrix "A" calls a function "inv" to find an inverse, and returns the result as a "matrix". //----------------------------------------------------------------------To go to the end of file, click end of fileClick characters below for a quick move.. A . . B . . C . . D . . E . . F . . G . . H .

. I . . J . . K . . L . . M . . N . . O . . P .

. Q . . R . . S . . T . . U . . V . . W . . X .

. Y . . Z .

//----------------------------------------------------------------------Green-colored name-tag with no link are units and constants Blue-colored name-tag has linked contents. Click it for a quick move. Below is an example.A .det determinant

//--------------------------------------------------------------// A//--------------------------------------------------------------_alpha = 0.0072973525376 // fine-structure const

1

Page 2: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x .A 10−10 x [m], angstrom

x .ac 4046.8564224 x [m^2] = 43560 x [ft^2], acre acos (x) inverse cosine functionacosd (x) inverse cosine function in degreeacosh (x) inverse hyperbolic cosine functionacot (x) inverse cotangent functionacotd (x) inverse cotangent function in degreeacoth (x) inverse hyperbolic cotangent functionacsc (x) inverse cosecant functionacscd (x) inverse cosecant function in degreeacsch (x) inverse hyperbolic cosecant functionA .add (i,j,s) elementary row operation, Ri=Ri+Rj*sA .all 0 if any a_ij is zero, column-first operationA .all1 double-returning, equivalent to A.all.all(1)A .any 1 if any a_ij is not zero A .any1 double-returning, equivalent to A.any.any(1)A .apoly ascending polynomialA .area area of three-sides triangleA .asa/asao triangle solution asec (x) inverse secant functionasecd (x) inverse secant function in degreeasech (x) inverse hyperbolic secant functionasin (x) inverse sine functionasind (x) inverse sine function in degreeasinh (x) inverse hyperbolic sine functionatan (x) inverse tangent functionatan2 (y,x) inverse tangent function with two argumentsatand (x) inverse tangent function in degreeatand2 (y,x) inverse tangent function in degreeatanh (x) inverse hyperbolic tangent functionx .atm 101.32501 x [kPa] = 760 x [mmHg], atmospherex .atmtec 98.0665 x [kPa], atm technical [kgf/cm^2]

x .au 1.496×1011 x [m], astronomical unit

2

Page 3: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

//--------------------------------------------------------------// B//--------------------------------------------------------------.B (a,b) beta function B(x , y ) dot-only

A .backsub n×(n+1) matrix, backward substitution

x .bar 100 x [kPa], barx .bbl 0.159 x [m^3], barrel (petroleum) // _barrelx .bhp 9.810657 x [kW], boiler horsepowerpoly .binom (n) binomial polynomial.bisect (a,b, f(x)) bisection to find a root, dot-only.blkdiag (...) equivalent to .diagcat(...), block diagonalx .BTU 1.0550559 x [kJ]

x .BTUph 0.29307108×10−3 x [kW], BTU/h

x .BTUpm 17.584265×10−3 x [kW], BTU/min

x .BTUps 1.0550559 x [kW], BTU/s

//--------------------------------------------------------------// C//--------------------------------------------------------------_c0 = 2.99792458 x 10^8 // speed of light [m/s]x .c Celsius to other temperatures, return Kelvin x .c2f 1.8 x+32 [F], Celsius to Fahrenheitx .c2k x+273.15 [K], Celsius to Kelvinx .c2r 1.8 x+491.67 [R], Celsius to Rankine x .Cal 4.1868 x [kJ], kilo caloriex .cal 0.0041868 x [kJ], calorie

x .calph 1.1163×10−6 x [kW], calorie/h

x .calpm 0.06978×10−3x [kW], calorie/min

x .calps 0.0041868 x [kW], calorie/s

x .cc 10−6 x [m^3], milliliter or cubic centimeter

3

Page 4: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

cbrt (x) cubic root, x^(1/3).ceil (x) integer near ∞x .ceil integer near ∞A .chol Choleski decomposition

Cint Cint ( x )= (1 / x )∫0

x

¿¿

A .circle a circle passing three pointsx .cm 0.01 x [m], centimeter

x .cm2 10−4 x [m^2], square centimeter

x .cm3 10−6 x [m^3], milliliter or cubic centimeter

x .cmAq 0.0980638 x [kPa], cm of waterx .cmHg 1.3322368 x [kPa], cm of mercuryx .cmps2 0.01 x [m/s^2]W .col (j) column vector, W(*,j)A .colabs column absoluteA .coldel (j) column deleteA .coldet (j) j-th column determinantA .colend A(*,end), A.endcolA .colins (j,B) insert B at j-th columnA .colskip (k) if k>0, 1,1+k,1+2k ... else ... n-2k,n-k,nA .colswap (i,j) swap i-th and j-th columnsA .colunit A.unit, each column is x^T x = 1p .compan companion matrix whose eigenvalues are the roots of p(x)A .cond condition number, A.norminf*A.inv.norminfA .conj complex conjugate, equivalent to ~AA .conjtr conjugate transpose, equivalent to A'.corrcoef (A,B) correlation coefficientcos (x) cosine functioncosd (x) cosine function in degreecosh (x) hyperbolic cosine functioncot (x) cotangent functioncotd (x) cotangent function in degree

4

Page 5: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

coth (x) hyperbolic cotangent function.cross (A,B) cross productcsc (x) cosecant functioncscd (x) cosecant function in degreecsch (x) hyperbolic cosecant functionA .cumprod cumulative productA .cumsum A~ = A.cumsump .cumsum ∑ p=p . ,cumulative sum

cumtrapz(x,y) cumulative trapezoidal rulex .Cup 284.130625×10−6 x [m^3], cup(UK)

x .cup 236.588×10−6 x [m^3], cup(US)v .cyl read in cylindrical coordinatez .cyl from cylindrical to rectangular coordinates

//--------------------------------------------------------------// D//--------------------------------------------------------------x .day 86400 x [s].decimal (x) = x - .round(x)/x/A/p/ .decimal deviation from the closest integer z .deg deg = atan(y/x) * 180/pi (in degree)csys.deg angles in the degree system.del (f) (a,b,c) gradient at (a,b,c) for f(x,y,z) dot-only.del* (u,v,w)(a,b,c) divergence dot-only.del^ (u,v,w)(a,b,c) curl dot-only.del2 (f)(a,b,c) Laplacian dot-only.del[] .x1.x2 ... .xn (f)(c1,c2,...,cn) gradient dot-only.del[][].x1.x2 ... .xn (f1,f2,...,fm) (c1,c2,...,cn) dot-onlyp .denom (nmax=10000) returns an integer denominator up to nmax A .det determinant/x/A/p/ .dfact double factorial of x, x(x-2)(x-3)... .diag (A,k=0) diagonal matrixW .diag (k) diagonal vector.diagcat (A1,A2,...) A1 \_ A2 \_ ..., diagonal concatenation

5

Page 6: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

A .diagm (k) .diag(A,k) for vectors, otherwise zero off-diagsA .diff A` = A.diff, finite-differencep .diff Δ p=p .'=p , finite difference

cs .dir direction cosines of a coordinate system.div (a,b) quotient q in a = bq+r dot-only.divisor (n) divisors, .divisor(10) = [1,2,5,10]x .dL 0.0001 x [m^3], deciliter.dot (A,B) A ** B dot product dot-onlyA .dpoly descending polynomialx .dyne 10−8x [kN], dyne // _dyn

//--------------------------------------------------------------// E//--------------------------------------------------------------_e = 2.718281828459045 // exp(1)_eps = 2.22e-16 // machine epsilon in Cemmath_e0 = 8.854187817 x 10^-12 // electric const [F/m]_eC = 1.602176487 x 10^-19 // elementary charge [C]_eV = 1.7827 x 10^-36 // electron volt [kg].E1 (x) exponential integral, expint(x).Ei (x) int_-inf^x exp(t)/t dt.e_k (n) k-th unit vector in an n-dimension dot-onlyA .eig return eigenvaluesA .eiginvpow (shift) eigenvalue by inverse power methodA .eigpoly eigenpolynomialA .eigpow (shift) eigenvalue by power methodA .eigvec (lam) eigenvecter(s)A .end real part of A(end,end)W .entry (matrix) entry of elements, W.(matrix)erf (x) error functionerfc (x) complementary error functionx .erg 10−10 x [kJ], erg

p .even a0+a2 x2+a4 x

4+a6 x6+…

6

Page 7: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

exp (x) exponential functionexpint (x) exponential integral, expint(x)=.E1(x)expm (A) = I + A + A^2/2! + A^3/3! + ....expm1 (x) exp(x)-1A .ext (m,n,s) extend A more with m rows, n columns .eye (m,n=m) identity matrix

//--------------------------------------------------------------// F//--------------------------------------------------------------_F = 96485.33977318 // Faraday const [C/mol]x .f Fahrenheit to other temperatures, return Kelvinx .f2c (x−32)/1.8 [C], Fahrenheit to Celsius

x .f2k (x+459.67) /1.8 [K] , Fahrenheit to Kelvin

x .f2r x+459.67 [R] , Fahrenheit to Rankine.fact (x) factorial, x(x-1)(x-2) ...factor (x) factorization, .factor(10) = [ 2,5 ]/x/A/p/ .fact factorial of x, x(x-1)(x-2)... A .false index for zero elementsA .find A.true, inbdex for nonzero elements.fix (x) integer near 0x .fix integer near 0A .fliplr reverse columns, flip left-rightA .flipud reverse rows, flip upside-down.floor (x) integer near -∞x .floor integer near -∞x .Floz 28.4130625×10−6 x [m^3], ounce(UK)

x .floz 29.5735×10−6 x [m^3], ounce(US)poly .format(string) set the format for screen outputA .forsub nx(n+1) matrix, forward substitutionx .ft 0.3048 x [m], feetx .ft2 0.09290304 x [m^2], square feetx .ft3 0.028316846592 x [m^3], cubic feet

7

Page 8: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x .ftlbph 0.3766161×10−6 x [kW], ft.lbf/h

x .ftlbpm 0.022596965×10−3 x [kW], ft.lbf/min

x .ftlbps 1.3558179×10−3 x [kW], ft.lbf/s

x .ftph 0.0000846667 x [m/s], ft/h

x .ftphs 8.4666667×10−5 x [m/s^2]

x .ftpm 0.00508 x [m/s], ft/minx .ftps 0.3048 x [m/s], ft/sx .ftps2 0.3048 x [m/s^2]

//--------------------------------------------------------------// G//--------------------------------------------------------------_G = 6.673 x 10^-11 // gravitational [m^3/(kg.s^2)]_g = 9.80665 // earth's gravity [m/s^2]_G0 = 7.7480917004 x 10^-5 // conductance quantum [ohm^-1]_gamma = 0.5772156649015329 // Euler-Mascheroni constant_gc = 32.174 // earth's gravity in British unit [ft/s^2]

.G (x) .G(x)=(x-1)!, Gamma function Γ (x ), dot-only

x .g 0.001 x [kg], gramx .Gal 0.00454609 x [m^3], gallon(UK) // _Gallonx .gal 0.00378541 x [m^3], gallon(US) // _gallonA .gausselim Gauss-elimination without pivotA .gaussjord Gauss-Jordan elimination with pivotA .gausspivot Gauss-elimination with pivot.gcd (a,b) greatest common divisor dot-onlyx .Gill 142.0653125×10−6 x [m^3], gill(UK)

x .gill 118.2941×10−6 x [m^3], gill(US)

x .GJ 106 x [kJ], giga Joule

x .GN 106 x [kN], giga newton

x .GPa 10−6 x [kPa], giga Pascal

8

Page 9: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x .gpcm3 1000 x [kg/m^3], gram per cm^3x .gpL x [kg/m^3], gram per liter

x .gr 6.479891×10−5 x [kg], grain

x .grpGal 0.014253767 x [kg/m^3], grain/gal(UK)x .grpgal 0.017118069 x [kg/m^3], grain/gal(US)x .gry 31556952 x [s] // gregorian year

x .GW 106 x [kW], giga Watt

//--------------------------------------------------------------// H//--------------------------------------------------------------_h = 6.62606896 x 10^-34 // Planck's const [J.s].H (x) Heaviside function H (x ) dot-only

.H_n (x) Hermite polynomial H n(x ) dot-only

.H1_nu (x) Hankel function, H ν(1)( x) dot-only

.H2_nu (x) Hankel function, H ν(2 )(x) dot-only

poly .H (n) Hermite polynomial Hn(x )x .ha 1000 x [m^2], hectarematrix .hank (A,B) Hankel matrixA .hess eigenvalue-preserving Hessenberg matrixA .high (m) reshape in m-rows matrix .hilb (n) Hilbert matrix.horzcat (A1,A2, ...) A_1 | A_2 | ... // horizontal concatenation x .hour 3600 x [s]x .hp 0.74569987 x [kW], horsepower(international) x .hPa 0.1 x [kPa], hecto Pascal

x .hph 2.6845195×103 x [kJ], // _hp*_hr

x .hpm 0.73549875 x [kW], horsepower(metric)x .hr 3600 x [s]hypot (x1,x2,...) .norm2(x1,x2,...)=sqrt(x1^2+x2^2+...)

9

Page 10: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

//--------------------------------------------------------------// I//--------------------------------------------------------------.I (m,n=m) identity matrix I=(δij ) dot-only

.I_nu (x) Bessel functions I ν (x) dot-only

A .i (k) k=i+m( j−1), i of (i,j) for linear index k

A .ij (i,j) k=i+m( j−1), linear index k for (i,j) W .imag imaginary partx .in 0.0254 x [m], inch

x .in2 6.4516×10−4 x [m^2], square inch

x .in3 16.387064×10−6 x [m^3], cubic inch

x .inAq 0.249089 x [kPa], inch of waterx .inHg 3.386389 x [kPa], inch of mercury

x .inphs 7.0555556×10−6 x [m/s^2]

x .inps2 0.0254 x [m/s^2]A .ins (i,j,B) insert B at (i,j) position.integ (a,b, f(x)) indefinite integral, dot-only.interp (X,F) polynomial for interpolation of F(X)A .inv inverse matrix

p .inv 1 / a0+(1 / a1) x+(1 / a2 )x2+…+¿

p .invtay a0+a1 x+2 !a2 x2+3 ! a3 x

3+…+n! an xn

A .ipos (x) return an index, ak≤ x≤ak+1

p .iratio shows a rational approximation .isprime (x) return (1) if x is a prime number A .isreal returns 1 if A is real, otherwise return 0A .issquare returns 1 if A is square

//--------------------------------------------------------------// J//--------------------------------------------------------------x .J 0.001 x [kJ], Joule

10

Page 11: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

A .j (k) k=i+m( j−1), j of (i,j) for linear index k

.J_nu (x) Bessel functions Jν (x ) dot-only

.j_n (x) spherical Bessel functions dot-onlymatrix.jord (a,b) Jordan matrix A .jord (i) eliminate rows above and below a_ii x .jyr 31557600 x [s] // julian year

//--------------------------------------------------------------// K//--------------------------------------------------------------_k = 1.3806504 x 10^-23 // Boltzmann const [J/K]_ke = 8.987551787368176 x 10^9 // Coulomb const [N.m^2/C^2].K_nu (x) Bessel functions K ν ( x ) dot-only

A .k (i,j) k=i+m( j−1), linear index k for (i,j)x .k Kelvin to other temperatures, return [K]x .k2c x−27.15 [C], Kelvin to Celsiusx .k2f 1.8 x−459.67 [F], Kelvin to Fahrenheitx .k2r 1.8 x [R], Kelvin to Rankinex .kcal 4.1868 x [kJ], kilo caloriex .kg x [kg], kilogram

x .kgf 9.80665×10−3x [kN], kilogram-force

x .kgfpcm2 98.0665 x [kPa], atm technicalx .kgpm3 x [kg/m^3] , kg per cubic meterx .kip 4.4482216 x [kN] = 1000x [lbf], kipx .kJ x [kJ], kilo Joulex .km 1000 x [m], kilometer

x .km2 106 x [m^2], square kilometer

x .km3 109 x [m^3], cubic kilometer

x .kmph 0.2777777778 x [m/s], km per hour //_km/_hrx .kmphs 0.27777777777 x [m/s^2]x .kmpm 16.666667 x [m/s], km per min

11

Page 12: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x .kmps 1000 x [m/s], km per sx .kN x [kN], kilo newtonx .kn 0.514444 x [m/s], knotx .kNm x [kN.m], kN.mx .kPa x [kPa], kilo Pascal.kron (A,B) A ^^ B kronecker product x .ksf 47.88027943 x [kPa], kip/ft^2x .ksi 6894.7572695 x [kPa], kip/in^2

x .kt 205.2×10−6 x [kg], carat

x .kW x [kW], kilo Wattx .kWh 3600 x [kJ], kiloWatt-hour // _kW*_hr

//--------------------------------------------------------------// L//--------------------------------------------------------------.L_n (x) Laguerre polynomial Ln(x) dot-onlypoly.L (n) Laguerre polynomialx .L 0.001 x [m^3], literx .lb 0.45359237 x [kg], pound-massx .lbm 0.45359237 x [kg], pound-mass

x .lbf 4.4482216×10−3 x [kN], pound-force

x .lbft 1.3558179×10−3 x [kN.m], lbf.ft

x .lbin 0.11298482×10−3 x [kN.m], lbf.in

x .lbpft3 16.018463 x [kg/m^3], lbm/ft^3x .lbpGal 99.776372 x [kg/m^3], lbm/gal(UK)x .lbpgal 119.82648 x [kg/m^3], lbm/gal(US)x .lbpin3 27679.905 x [kg/m^3], lbm/in^3.lcm (a,b) least common multiplier dot-onlypoly.left (string) set the left delimiter for screen outputp .len n+1 of n-th degree polynomialA .len/length max(m,n)

12

Page 13: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

lnG (x) lnG(x ), gammaln(x) in matlablog (x) natural log with base _elog1p (x) log(1+x)log2 (x) log with base 2log10 (x) log with base 10logm (A) inverse of expm(a,b) .logspan (n,g=1) 10.^( (log10(a),log10(b)).span(n,g=1) )A .longer max(m,n)A .lu LU decomposition, (L ,U )=A . lu

x .ly 9.4607×1015 x [m], light year

x .lyr 31622400 x [s] // leap year

//--------------------------------------------------------------// M//--------------------------------------------------------------_mu0 = 1.2566370614 x 10^-6 // magnetic const [N/A^2]_muB = 9.27400915 // Bohr magneton [J/T], T=tesla_m_e = 9.10938215 x 10^-31 // electron mass [kg]_m_m = 1.8835313 x 10^-28 // muon mass [kg]_m_n = 1.674927211 x 10^-27 // neutron mass [kg]_m_p = 1.672621637 x 10^-27 // proton mass [kg]_m_t = 3.16777 x 10^-27 // tau mass [kg]_m_u = 1.660538782 x 10^-27 // atomic mass [kg]A .m m, number of rowsx .m x [m], meterx .m2 x [m^2], square meterx .m3 x [m^3], cubic meterx .ma 320 x [m/s], speed of sound (mach)(a,h) .march (n,g=1) [ a, a+h(1),... , a+h(1+g+...+g^(n-2)) ].max (x1,x2, ... , xn) maximum dot-onlyA .max maximum elements p .max max \{ai \}

A .max1 maxa ij, equivalent to A.max.max(1)

13

Page 14: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

A .max1k/maxk linear index k for A.max1poly .maxcol(n=10) set the maximum column length for output A .maxentry absolute maximum elementp .maxentry max \{|ai |\}A .maxentryk linear index k for A.maxentryx .mb 0.1 x [kPa], millibar // _mbarA .mean mean elements

p .mean ∑i=0

n

ai /(n+1)

x .mg 10−6 x [kg], milligram

x .mi 1609.344 x [m] = 1760 x [yd], milex .mi2 2589988.110336 x [m^2], square mile

x .mi3 4.16818182544058×109 x [m^3], cubic mile.min (x1,x2, ... , xn) minimum dot-onlyx .min 60 x [s] // minuteA .min minimum elements p .min min \{ai \}

A .min1 minaij, equivalent to A.min.min(1)A .min1k/mink linear index k for A.min1A .minentry absolute minimum elementp .minentry min \{|a i |\}A .minentryk linear index k for A.minentryA .minor (i,j) minor by eliminating i-th row and j-th columnx .mipm 26.8224 x [m/s], mile per minx .mips 1609.344 x [m/s], mile per sx .MJ 1000 x [kJ], mega Joule

x .mJ 10−6 x [kJ], mill Joule

x .mL 10−6 x [m^3], milliliter or cubic centimeter

x .mm 0.001 x [m], millimeter

x .mm2 10−6 x [m^2], square millimeter

14

Page 15: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x .mm3 10−9 x [m^3], cubic millimeter

x .mmAq 0.00980638 x [kPa], mm of waterx .mmHg 0.133322368 x [kPa], mm of mercuryx .mmps2 0.001 x [m/s^2]x .MN 1000 x [kN], mega newtonA .mn m*n, total number of elements.mod (a,b) modulus a-b*floor(a/b) dot-onlyp .monic ¿¿x .MPa 1000 x [kPa], mega Pascalx .mph 0.44704 x [m/s], mile per hour // _mi/_hrx .mphr 0.0002777777778 x [m/s], meter per hourx .mphs 0.44704 x [m/s^2]x .mpm 0.016666667 x [m/s], meter per minutex .mps x [m/s], meter per second

x .mps2 x [m/s^2] , meter per square second

x .ms 0.001 x [s] // milli secondA .mul (i, s) elementary row operation, R_i = R_i * s x .mum 10−6 x [m], micron

x .mus 10−6 x [s] // micro second

x .MW 1000 x [kW], mega Watt

x .mW 10−6 x [kW], milli Watt

//--------------------------------------------------------------// N//--------------------------------------------------------------_NA = 6.02214179 x 10^23 // Avogadro's const [mol^-1]x .N 0.001 x [kN], newton.n_n (x) spherical Bessel functions, dot onlyA .n n, number of columnsp .n n, the hightest order of a polynomial

15

Page 16: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x .Ncm 0.01×10−3 x [kN.m], N.cm.ncr (n,r) combination nCr, n!/ ( (n-r)!r! ) dot-onlynextpow2(x) 2^n >= xp .newton (x) a0+a1 ( x−x1)+a2 ( x−x1) (x−x2 )+…x .Nm 0.001 x [kN.m], N.m

x .nm 10−9 x [m], nanometer

x .nmi 1852x [m], nautical mile

A .norm (p) p-norm (vector or matrix) .norm1 (x1,x2,…) |x1|+|x2|+|x3|+⋯.norm2 (x1,x2,…) √ x1

2+x22+x3

2+⋯

.norm22 (x1,x2,…) x12+ x2

2+x32+⋯

A .norm1 1-norm A .norm2 Frobenius norm, sqrt(A**A)A .norm22 A.norm22 = A.norm2^2 = A**AA .norminf infinite-norm.npr (n,r) permutation nPr, n!/ ( (n-r)! ) dot-onlyx .ns 10−9 x [s] // nano second

//--------------------------------------------------------------// O//--------------------------------------------------------------p .odd a1 x+a3 x

3+a5 x5+a7 x

7+….off 'dot-off' default mode, both modes work. dot-only.on 'dot-on' activates dot-only dot-only .ones (m,n=m) all-ones matrixcs.org origin of a coordinate systemx .oz 0.0283495 x [kg], ounce-mass

x .ozf 0.278014×10−3 x [kN], ounce-force

x .ozft 0.084738667×10−3 x [kN.m], ozf.ft

x .ozin 7.06156×10−6 x [kN.m], ozf.in

16

Page 17: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x .ozm 0.0283495 x [kg], ounce-massx .ozpGal 6.2360182 x [kg/m^3], ozm/gal(UK)x .ozpgal 7.4891491 x [kg/m^3], ozm/gal(US)x .ozpft3 1.00115 x [kg/m^3], ozm/ft^3x .ozpin3 1729.989044 x [kg/m^3], ozm/in^3

//--------------------------------------------------------------// P//--------------------------------------------------------------_phi0 = 2.067833667 x 10^-15, magnetic flux quantum [Wb]v .P coordinate ϕ in (R ,ϕ ,θ) coordinate.P_n (x) Legendre polynomial dot-onlypoly .P (n) Legendre polynomialx .Pa 0.001 x [kPa], PascalA .pass line, parabola, cubic csys.pass180 pass through -x coordinate, 0 <= t < 2*picsys.pass0 pass through +x coordinate, -pi < t <= pix .pc 3.0857×1016 x [m], parsecA .pcent a_ij/sum(a_ij) * 100x .pdl 0.138255×10−3 x [kN], poundal

x .pdlft 0.042140124×10−3 x [kN.m], pdl.ft

x .pdlin 3.511677×10−6 x [kN.m], pdl.inA .plot plotA .plu A = PLU decomposition.pm (n) 1 if n is even, otherwise (-1) dot-onlyx .pm 1 if x is even, otherwise (-1) A .pm (-1)^(i+j) a_ij

p .pm a0−a1 x+a2 x2−a3 x

3+…+ (−1 )nanxn

.polyfit (X,F, kth) same as .regress(X,F,kth) dot-onlypow (x,a) x^ap .pow (k) a0+a1 x

k+a2x2k+a3 x

3k…+an xnk

pow2 (x) 2^x

17

Page 18: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

pow10 (x) 10^x.primes (a,b) prime numbers between a and bA .prod product of elements

p .prod ∏i=0

n

ai

A .prod1 equivalent to A.prod.prod(1)x .psf 0.04788027943 x [kPa], lbf/ft^2

.psi (x) ψ (n )=−γ+ 11+ 1

2+1

3+⋯+ 1

n−1 dot only

x .psi 6.8947572695 x [kPa], lbf/in^2

x .Pt 568.26125×10−6 x [m^3], pint(UK) // _Pint

x .pt 473.1765×10−6 x [m^3], pint(US) // _pintA .pushd push-down with top rowA .pushl push-left with rightmost columnA .pushr push-right with leftmost columnA .pushu push-up with bottom rowx .py 3.30579 x [m^2], pyung

//--------------------------------------------------------------// Q//--------------------------------------------------------------A .qr A = QR decompositionx .Qt 1136.5225×10−6 x [m^3], quart(UK) // _Quart

x .qt 946.35296×10−6 x [m^3], quart(US) // _quart

p .quad (r,s) divisor x2+rx+s by Bairstow method

//--------------------------------------------------------------// R//--------------------------------------------------------------_R = 8.31447247122 // molar gass const [J/(mol.K)]_Rinf = 1.0973731568527 x 10^7 // Rydberg const [m^-1]x .r Rankine to other temperatures, return [K]

18

Page 19: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x .r2c (x−491.67)/1.8 [C], Rankine to Celsius

x .r2f x−459.67 [F], Rankine to Fahrenheitx .r2k x / 1.8 [K], Rankine to Kelvin v .R coordinate R in (R ,ϕ ,θ) coordinate

v .r coordinate r in (r , θ , z) coordinatez .r |z| = sqrt( x*x + y*y )csys.rad angles in the radian system.rand (m,n=m) randon number matrix between 0 and 1A .rank rank of a matrix AA .ratio (denom=10000) shows a rational approximationp .ratio shows a rational approximationA .ratio1 denomenator of a rational approximation A .read (string) read A from a fileW .real real partv .rec read in rectangular coordinatecsys.rec rectangular coordiante system.regress (X,F, mftn) matrix for regression dot-only.rem (a,b) modulus a-b*fix(a/b) dot-onlyA .repmat (m,n=m) repeat a tile-shaped copyingA .resize (m,n) resize a matrix by copyingA .rev reverse elements, rotating 180 degreep .rev an+an−1 x+an−2 x

2+an−3 x3+…+a0 x

n

poly .right (string) set the right delimiter for screen output.roots ( … ) a polynomial with knwon roots dot-onlyA .rot90 rotate 90 degree (counter-clockwise)A .rotm90 rotate -90 degree

A .roots (x−x1 ) (x−x2 )⋯( x−xn)

.round (x) integer near x/x/A/p/ .round nearest integer to xW .row (i) row vector, A(i,*)A .rowabs row absoluteA .rowdel (i) row deleteA .rowdet (i) i-th row determinant

19

Page 20: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

A .rowend A(end,*), A.endrowA .rowins (i,B) insert B at i-th row, A.insrowA .rowskip (k) if k>0, 1,1+k,1+2k ... else ... m-2k,m-k,mA .rowswap (i,j) elementary row operation, swap rowsA .rowunit each row is xT x=x1

2+x22+⋯+xn

2=1

//--------------------------------------------------------------// S//--------------------------------------------------------------_sigma = 5.6704 x 10^-8 // Stefan-Boltzmann[W/(m^2.K^4)]x .s x [s] // secondA .sas/saso triangle solution A .sdev standard deviation sec (x) secant function.secant (a,b, f(x)) secant method for root finding dot-onlysecd (x) secant function in degreesech (x) hyperbolic secant functionp .shift (c) a0+a1 (x−c )+a2 ( x−c )2+…+an(x−c )

n

A .shorter min(m,n).sign (x) (1) if x > 0, (-1) if x < 0 and (0) if x = 0x .sign (1) if x>0, (-1) if x<= and (0) if x=0sin (x) sine functionsinc (x) sin(x)/xsind (x) sine function in degreesinh (x) hyperbolic sine function

Sint (x) Sint ( x )=(1 / x )∫0

x

sin (t ) / t dt

A .size tuple, number of rows and columnsA .skewl (k) lower-triangular w.r.t the skew-diagonalA .skewu (k) upper-triangular w.r.t the skew-diagonalx .slug 14.5939 x [kg] = 32.174x [lbm], slug x .slugpft3 515.378711 x [kg/m^3], slug/ft^3x .slugpin3 890574.42 x [kg/m^3], slug/in^3

20

Page 21: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

A .solve nx(n+1) matrix, A.axb, solve Ax = b with (A|b)p .solve solution matrix(a,b) .span (n,g=1) [ x_1 = a, x_2, …, x_n = b ],dx_i=g dx_(i-1)v .sph read in spherical coordinate.spline (X,F) 3rd-order spline matrix dot-only.spline1 (X,F) 1st-order spline matrix dot-only.splinebc1 (X,F) 3rd-order spline matrix dot-only.splinebc2 (X,F) 3rd-order spline matrix dot-onlyA .spl (B) evaluation for matrixA .spldiff differentiate piecewise polynomials A .splint integrate piecewise polynomialsA .splplot plot piecewise polynomialssqrt (x) square rootsqrtm (A) from XX = AA .sss/ssso triangle solution with three sidesA .stat basic statisticsA .std standard deviation (a,b) .step (h) [ a, a+h, a+2h, ... ]W .sub (r)(c) submatrix, W..(r)(c)A .subdel (r)(c) delete submatrixA .sum sum of elements

p .sum ∑i=0

n

ai

A .sum1 equivalent to A.sum.sum(1).swap (#1,#2) swap two arguments dot-onlyA .swap (i,j) elementary row operation, swap rows, A.rowswap p .syndiv (c) p %% c = p.syndiv(c)p .syndiv (q) p %% q , synthetic division by polynomial q

//--------------------------------------------------------------// T//--------------------------------------------------------------v .T coordinate θ in (R ,ϕ ,θ) coordinate

v .t coordinate θ in (r , θ , z) coordinate

21

Page 22: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

z .t t = atan(y/x) (in radian).T_n (x) Tchebyshev polynmomial dot-onlypoly .T (n) Tchebyshev polynmomialtan (x) tangent functiontand (x) tangent function in degreetanh (x) hyperbolic tangent functionp .tay a0+a1 x+a2 x

2 / 2 !+a3 x3 / 3 !+…+an x

n / n !

x .Tbsp 14.20653125×10−6 x [m^3], tablespoon(UK)

x .tbsp 14.78676×10−6 x [m^3], tablespoon(US).tdma (a,b,c,d, na,nb) tridiagonal matrix algorithm dot-onlyx .Therm 0.10550559×106 x [kJ], therm(Europe)

x .therm 0.1054804×106 x [kJ], therm(US)x .todeg x * 180 / pi, radian to degreematrix.toep (A,B) toeplitz matrixx .torad x * pi / 180, degree to radianx .Ton 907.1847 x [kg], English ton-massx .ton 1000 x [kg], ton, metric ton-massx .Tonf 8.896443239 x [kN], English ton-forcex .tonf 9.80665 x [kN], ton-forcex .torr 0.133322368 x [kPa], mmHgA .tr transpose A .trace tracetrapz(x,y) area by trapezoidal ruleA .tril (k) lower-triangularA .triu (k) upper-triangularA .true index for nonzero elements/x/A/p/v/z/ .trun (eps=1.e-30) truncate if |x|<eps/x/A/p/v/z/ .trunk truncate with ϵ=10−k , k ≤16

x .Tsp 3.5516328125×10−6 x [m^3], teaspoon(UK)

x .tsp 4.92892×10−6 x [m^3], teaspoon(US)

22

Page 23: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

//--------------------------------------------------------------// U//--------------------------------------------------------------A .unit normalize each column vector (column-first)v .unit normalize a vertexz .unit normalize a complex numberp .up (k) a0x

k+a1 x1+k+a2 x

2+k+…+an xn+k

//--------------------------------------------------------------// V//--------------------------------------------------------------A .vander (nrow) Vandermonde matrix A .var variance.vertcat (A1,A2,...) A1 _ A2 _ ... // vertical concatenation

//--------------------------------------------------------------// W//--------------------------------------------------------------x .W 0.001 x [kW], Wattx .week 604800 x [s]x .Wh 3.6 x [kJ], Watt-hour // _W*_hrA .wide (n) A..n = A.wide(n), reshape in n-columnA .write (string) write A to a file

//--------------------------------------------------------------// X//--------------------------------------------------------------A .xrot/xrotd (theta) rotation around the x-axis v .xrot/xrotd (theta) rotation around the x-axis

//--------------------------------------------------------------// Y//--------------------------------------------------------------.Y_nu (x) Bessel function Y ν (x ) dot-only

23

Page 24: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x .yd 0.9144 x [m] = 3 x [ft], yardx .yd2 0.83612736 x [m^2], square yardx .yd3 0.764554857984 x [m^3], cubic yardx .ydph 0.000254 x [m/s], yard/hx .ydpm 0.015424 x [m/s], yard/minx .ydps 0.9144 x [m/s], yard/s.ym (year,month) print calendar, .ym(2012,8) dot-onlyx .yr 31536000 x [s] // non-leap yearA .yrot/yrotd (theta) rotation around the y-axis v .yrot/yrotd (theta) rotation around the y-axis

//--------------------------------------------------------------// Z//--------------------------------------------------------------_Z0 = 376.73031346177 // Impedance of vacuum [ohm].zeros (m,n=m) all-zeros matrixA .zrot/zrotd (theta) rotation around the z-axis (in degree) v .zrot/zrotd (theta) rotation around the z-axis

//--------------------------------------------------------------// end of lists//--------------------------------------------------------------

//----------------------------------------------------------------------//----------------------------------------------------------------------poly( a0,a1,a2, …, an ); // list of coefficientspoly( [a0,a1,a2,…,an] ); // a single matrixpoly( A ); // A is a matrix

[an, …,a2,a1,a0].poly; // general order, n >= 4 .[an, …,a2,a1,a0]; // general order, n >= 4 .[ a ] // constant polynomial.[ a,b ] // 1st-order poly, line y = ax+b.[ a,b,c ] // 2nd-order poly, parabola y = ax^2 + bx + c.[ a,b,c,d ] // 3rd-order poly, cubic y = ax^3 + bx^2 + cx +d

24

Page 25: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

p = poly[ n+1 ].i ( f(i) ) p = poly[ 0,n ].i ( f(i) )

A general for the coefficient function is

p ( x )=f (a ) xa+ f (a+m ) xa+m+f (a+2m) xa+2m+…p = poly[ a,b, m=1 ] .i ( f(i) )

25

Page 26: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

Description of functions

[ A ]

-----------------------------------------------------------------Inverse Cosine Function double acos(double x) complex acos(complex z) matrix acos(matrix A)----------------------------------------------------------------------

acos ( x )=cos−1 x−1≤x ≤1 ,0≤acos ( x )≤π

cos−1 z=−i log (z+√ z2−1 )

#> acos(0.5); cos(ans); ans = 1.0471976 ans = 0.5

#> acos( 2+0i ); cos(ans); ans = 0 - 1.31696! ans = 2 + 0!

#> acos( [ 0.5, 2+0i ] ); cos(ans); ans = [ 1.0472 + i 5.55112e-017 0 - i 1.31696 ] ans = [ 0.5 - i 4.80741e-017 2 ]

#> plot.x(-1,1) ( acos(x) );

----------------------------------------------------------------------Inverse Cosine Function in Degree double acosd(double x) complex acosd(complex z) matrix acosd(matrix A)

26

Page 27: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------

acosd ( x )=acos (x ) 180π

−1≤x ≤1 ,0≤acosd ( x )≤180

#> acosd(0.5); cosd(ans); ans = 60 ans = 0.5

#> acosd( 2+0i ); cosd(ans); ans = 0 - 75.4561! ans = 2 + 0!

#> acosd( [ 0.5, 2+0i ] ); cosd(ans); ans = [ 60 + i 3.18055e-015 0 - i 75.4561 ] ans = [ 0.5 - i 4.80741e-017 2 ]

----------------------------------------------------------------------Inverse Hyperbolic Cosine Function double acosh(double x) complex acosh(complex z) matrix acosh(matrix A)----------------------------------------------------------------------

acosh ( x )=cosh−1 x=log ( x+√x2−1 )1≤x<∞ ,0≤acosh (x )<∞

cosh−1 z=log (z+√ z2−1)

The return value of acosh is the positive inverse or the complex inverse with the smallest argument.

#> acosh(pi); cosh(ans); ans = 1.8115263 ans = 3.1415927

#> acosh( 0i ); cosh(ans); ans = 0 + 1.5708! ans = 6.12323e-017 + 0!

#> acosh( [ pi, 0i ] ); cosh(ans); ans = [ 1.81153 0 + i 1.5708 ] ans = [ 3.14159 6.12323e-017 ]

27

Page 28: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> plot.x(1,5) ( acosh(x) );

----------------------------------------------------------------------Inverse Cotangent Function double acot(double x) complex acot(complex z) matrix acot(matrix A)----------------------------------------------------------------------

acot ( x )=atan (1 / x )

−∞<x<∞ ,− π2<acot ( x )< π

2

cot−1 z=12i log( iz+1

iz−1 )#> acot( 2 ); cot(ans); ans = 0.46364761 ans = 2

#> acot( 2i ); cot(ans); ans = 0 - 0.549306! ans = 0 + 2!

#> acot( [ 2, 2i ] ); cot(ans); ans = [ 0.463648 + i 5.55112e-017 0 - i 0.54930 ] ans = [ 2 - i 2.77556e-016 0 + i 2 ]

#> plot.x(-50,-0.01) ( acot(x) ); plot+.x(0.01,50) ( acot(x) );

----------------------------------------------------------------------Inverse Cotangent Function in Degree

28

Page 29: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

double acotd(double x) complex acotd(complex z) matrix acotd(matrix A)----------------------------------------------------------------------

acotd ( x )=acot ( x ) 180π

−∞<x<∞ ,−90<acotd ( x )<90

#> acotd( 2 ); cotd(ans); ans = 26.565051 ans = 2

#> acotd( 2i ); cotd(ans); ans = 0 - 31.4729! ans = 0 + 2!

#> acotd( [ 2, 2i ] ); cotd(ans); ans = [ 26.5651 + i 3.18055e-015 0 - i 31.4729 ] ans = [ 2 - i 2.77556e-016 0 + i 2 ]

----------------------------------------------------------------------Inverse Hyperbolic Cotangent Function double acoth(double x) complex acoth(complex z) matrix acoth(matrix A)----------------------------------------------------------------------

acoth ( x)=atanh (1 / x )x←1,1<x ,−∞<acoth ( x )<∞

coth−1 z=12

log z+1z−1

#> acoth( 2 ); coth(ans); ans = 0.54930614 ans = 2

#> acoth( 0.5+0i ); coth(ans); ans = 0.549306 - 1.5708! ans = 0.5 + 4.59243e-017!

#> acoth( [ 2, 0.5+0i ] ); coth(ans); ans = [ 0.549306 0.549306 - i 1.5708 ] ans = [ 2 0.5 + i 4.59243e-017 ]

29

Page 30: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> plot.x(1.01,50) ( acoth(x) ); plot+.x(-50,-1.01) ( acoth(x) );

----------------------------------------------------------------------Inverse Cosecant Function double acsc(double x) complex acsc(complex z) matrix acsc(matrix A)----------------------------------------------------------------------

acsc ( x )=asin (1 / x)

x≤−1 ,1≤x ,− π2≤acsc ( x )≤ π

2

csc−1 z=−i log( iz +√1− 1z2 )

#> acsc( 2 ); csc(ans); ans = 0.52359878 ans = 2

#> acsc( 0.5+0i ); csc(ans); ans = 1.5708 - 1.31696! ans = 0.5 + 2.65144e-017!

#> acsc( [ 2, 0.5+0i ] ); csc(ans); ans = [ 0.523599 + i 5.55112e-017 1.5708 - i 1.31696 ] ans = [ 2 - i 1.92296e-016 0.5 + i 2.65144e-017 ]

#> plot.x( 1,50 ) ( acsc(x) ); plot+.x(-50,-1) ( acsc(x) );

----------------------------------------------------------------------

30

Page 31: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

Inverse Cosecant Function in Degree double acscd(double x) complex acscd(complex z) matrix acscd(matrix A)----------------------------------------------------------------------

acscd ( x )=acsc (x) 180π

x≤−1 ,1≤x ,−90≤acscd (x)≤90

#> acscd( 2 ); cscd(ans); ans = 30 ans = 2

#> acscd( 0.5+0i ); cscd(ans); ans = 90 - 75.4561! ans = 0.5 + 2.65144e-017!

#> acscd( [ 2, 0.5+0i ] ); cscd(ans); ans = [ 30 + i 3.18055e-015 90 - i 75.4561 ] ans = [ 2 - i 1.92296e-016 0.5 + i 2.65144e-017 ]

----------------------------------------------------------------------Inverse Hyperbolic Cosecant Function double acsch(double x) complex acsch(complex z) matrix acsch(matrix A)----------------------------------------------------------------------

acsch (x )=asinh (1 / x )−∞<x<∞ ,−∞<asinh ( x )<∞

csch−1 z=log( 1z+√ 1

z2 +1)#> acsch( 0.5 ); csch(ans); ans = 1.4436355 ans = 0.5

#> acsch( 2i ); csch(ans); ans = -5.55112e-017 - 0.523599! ans = -1.92296e-016 + 2!

#> acsch( [ 0.5, 2i ] ); csch(ans); ans = [ 1.44364 -5.55112e-017 - i 0.523599 ] ans = [ 0.5 -1.92296e-016 + i 2 ]

31

Page 32: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> plot.x(-5,-.01) ( acsch(x) ); plot+.x(.01,5) ( acsch(x) );

---------------------------------------------------------------------- matrix A.add(double i, double j, double s)----------------------------------------------------------------------elementary row operation, Ri=R i+sR j

A=[ Ri

⋯R j

] where Ri is i-th row. A.add(i,j, s) = [Ri+s R j

⋯R j

] #> A = [ 2,1,4 ; -1,3,5 ]; A = [ 2 1 4 ] [ -1 3 5 ]

#> A.add(2,1, 4); // R_2 = R_2 + R_1 * 4 ans = [ 2 1 4 ] [ 7 7 21 ]

---------------------------------------------------------------------- matrix A.all // column-first operation

double A.all1 // equivalent to A.all.all(1)----------------------------------------------------------------------0 if any a ij is zero, otherwise 1

#> A = [3,4; 0,0]; B = [1,0; 4,0]; // multi-rows (column-first) A = [ 3 4 ] [ 0 0 ] B = [ 1 0 ] [ 4 0 ]

#> A.all; // operation on each column ans = [ 0 0 ]

32

Page 33: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> B.all; ans = [ 1 0 ]

#> A(); A().all; // single-row with columnwise countingans = [ 3 0 4 0 ]

ans = [ 0 ]

#> A.all1; // equivalent to A.all.all(1) ans = 0 ---------------------------------------------------------------------- matrix A.any // column-first operation

double A.any1 // equivalent to A.any.any(1)----------------------------------------------------------------------1 if any a ij is not zero, otherwise 0

#> A = [3,4; 0,0]; B = [1,0; 4,0]; // multi-rows (column-first) A = [ 3 4 ] [ 0 0 ] B = [ 1 0 ] [ 4 0 ]

#> A.any; ans = [ 1 1 ]

#> B.any; ans = [ 1 0 ]

#> A(); A().any; // single-rowans = [ 3 0 4 0 ]

ans = [ 1 ]

#> A.any1; // equivalent to A.any.any(1) ans = 1

---------------------------------------------------------------------- poly A.apoly poly A.poly ----------------------------------------------------------------------convert a matrix into a polynomial by ascending order

#> A = (1:8)._3; A = [ 1 4 7 ] [ 2 5 8 ] [ 3 6 0 ]

33

Page 34: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.apoly; // note that the order is x^7 ans = poly( 1 2 3 4 5 6 7 8 ) = +8x^7 +7x^6 +6x^5 +5x^4 +4x^3 +3x^2 +2x +1

---------------------------------------------------------------------- double A.area ----------------------------------------------------------------------[ a, b, c ] .area // area of a three-sides triangle

#> [ 3, 4, 5 ].area; ans = 6

----------------------------------------------------------------------Inverse Secant Function double asec(double x) complex asec(complex z) matrix asec(matrix A)----------------------------------------------------------------------

asec ( x )=acos (1 / x)x≤−1 ,1≤x ,0≤asec ( x )≤π

sec−1 z=−i log ( 1z+√ 1

z2 −1)#> asec( 2 ); sec(ans); ans = 1.0471976 ans = 2

#> asec( 0.5+0i ); sec(ans); ans = -0 - 1.31696! ans = 0.5 + 0!

#> asec( [ 2, 0.5+0i ] ); sec(ans); ans = [ -1.0472 + i 5.55112e-017 -0 - i 1.31696 ] ans = [ 2 - i 1.92296e-016 0.5 ]

#> plot.x( 1,50 ) ( asec(x) ); plot+.x(-50,-1 ) ( asec(x) );

34

Page 35: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------Inverse Secant Function in Degree double asecd(double x) complex asecd(complex z) matrix asecd(matrix A)----------------------------------------------------------------------

asecd ( x )=asecd (x ) 180π

x≤−1 ,1≤x ,0≤asec ( x )≤180

#> asecd( 2 ); secd(ans); ans = 60 ans = 2

#> asecd( 0.5+0i ); secd(ans); ans = -0 - 75.4561! ans = 0.5 + 0!

#> asecd( [ 2, 0.5+0i ] ); secd(ans); ans = [ -60 + i 3.18055e-015 -0 - i 75.4561 ] ans = [ 2 - i 1.92296e-016 0.5 ]

----------------------------------------------------------------------Inverse Hyperbolic Secant Function double asech(double x) complex asech(complex z) matrix asech(matrix A)----------------------------------------------------------------------

asech (x )=acosh (1 / x)0<x ≤1 ,0≤asech ( x )<∞

sech−1 z=log( 1z+√ 1

z2 −1)#> asech( 0.5 ); sech(ans); ans = 1.3169579 ans = 0.5

#> asech( 2+0i ); sech(ans); ans = -5.55112e-017 - 1.0472! ans = 2 - 1.92296e-016!

#> asech( [ 0.5, 2+0i ] ); sech(ans); ans = [ 1.31696 -5.55112e-017 - i 1.0472 ] ans = [ 0.5 2 - i 1.92296e-016 ]

35

Page 36: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> plot.x(0.001,1) ( asech(x) );

----------------------------------------------------------------------Inverse Sine Function double asin(double x) complex asin(complex z) matrix asin(matrix A)----------------------------------------------------------------------

asin ( x )=sin−1 x

−1≤x ≤1 ,− π2≤asin (x )≤ π

2sin−1 z=−i log (iz+√1−z2 )

#> asin(0.5); sin(ans); ans = 0.52359878 ans = 0.5

#> asin( 2+0i ); sin(ans); ans = 1.5708 + 1.31696! ans = 2 + 8.75243e-016!

#> asin( [ 0.5, 2+0i ] ); sin(ans); ans = [ 0.523599 + i 5.55112e-017 1.5708 + i 1.31696 ] ans = [ 0.5 + i 4.80741e-017 2 + i 8.75243e-016 ]

#> plot.x(-1,1) ( asin(x) );

----------------------------------------------------------------------Inverse Sine Function in Degree

36

Page 37: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

double asind(double x) complex asind(complex z) matrix asind(matrix A)----------------------------------------------------------------------

asind ( x )=asin ( x ) 180π

−1≤x ≤1 ,−90≤asin ( x )≤90

#> asind(0.5); sind(ans); ans = 30 ans = 0.5

#> asind( 2+0i ); sind(ans); ans = 90 + 75.4561! ans = 2 + 4.9065e-016!

#> asind( [ 0.5, 2+0i ] ); sind(ans); ans = [ 30 + i 3.18055e-015 90 + i 75.4561 ] ans = [ 0.5 + i 4.80741e-017 2 + i 4.9065e-016 ]

----------------------------------------------------------------------Inverse Hyperbolic Sine Function double asinh(double x) complex asinh(complex z) matrix asinh(matrix A)----------------------------------------------------------------------

asinh ( x )=log (x+√ x2+1 )−∞<x<∞ ,−∞<asinh ( x )<∞

sinh−1 z= log ( z+√z2+1 )

#> asinh( 0.5 ); sinh(ans); ans = 0.48121183 ans = 0.5

#> asinh( 2i ); sinh(ans); ans = 1.31696 + 1.5708! ans = 1.06058e-016 + 2!

#> asinh( [ 0.5, 2i ] ); sinh(ans); ans = [ 0.481212 1.31696 + i 1.5708 ] ans = [ 0.5 1.06058e-016 + i 2 ]

37

Page 38: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> plot.x( -50,50 ) ( asinh(x) );

----------------------------------------------------------------------Inverse Tangent Function double atan(double x) complex atan(complex z) matrix atan(matrix A)----------------------------------------------------------------------

atan (x )=tan−1 x

−∞<x<∞ ,− π2<atan ( x )< π

2

tan−1 z= i2

log i+zi−z

#> atan(1); tan(ans); ans = 0.78539816 ans = 1

#> atan( 0.5i ); tan(ans); ans = 0 + 0.549306! ans = 0 + 0.5!

#> atan( [ 1, 0.5i ] ); tan(ans); ans = [ 0.785398 0 + i 0.549306 ] ans = [ 1 0 + i 0.5 ]

#> plot.x( -20,20 ) ( atan(x) );

---------------------------------------------------------------------- double atand(double x)

38

Page 39: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

complex atand(complex z) matrix atand(matrix A)----------------------------------------------------------------------

atand ( x )=atan ( x ) 180π

−∞<x<∞ ,−90<atan ( x )<90

#> atand(1); tand(ans); ans = 45 ans = 1

#> atand( 0.5i ); tand(ans); ans = 0 + 31.4729! ans = 0 + 0.5!

#> atand( [ 1, 0.5i ] ); tand(ans); ans = [ 45 0 + i 31.4729 ] ans = [ 1 0 + i 0.5 ]

----------------------------------------------------------------------Inverse Tangent Function with two arguments double atan2(double y, double x) matrix atan2(double y, matrix x) matrix atan2(matrix y, double x) matrix atan2(matrix y, matrix x)----------------------------------------------------------------------

atan 2 ( y , x )=tan−1 yx

−∞<x<∞ ,−∞< y<∞,−π<atan2 ( y , x )≤π

#> atan2( 1, 1 ) ; // first quadrant, x = 1, y = 1 ans = 0.78539816

#> atan2( 1, -1 ); // second quadrant, x = -1, y = 1 ans = 2.3561945

#> atan2( -1, -1 ); // third quadrant, x = -1, y = -1 ans = -2.3561945

#> atan2( -1, 1 ); // fourth quadrant, x = 1, y = -1 ans = -0.78539816

For a pair of rows and columns with the same dimension, operation applies for a pair of elements (x i , y i)

39

Page 40: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> atan2( [1,1,-1,-1], [1,-1,-1,1] ); ans = [ 0.785398 2.35619 -2.35619 -0.785398 ]

Otherwise, a structure similar to the Kronecker product is obtained

#> atan2( [1;0.5;-0.5;-1], [1,-1,-1,1] ); ans = [ 0.785398 2.35619 2.35619 0.785398 ] [ 0.463648 2.67795 2.67795 0.463648 ] [ -0.463648 -2.67795 -2.67795 -0.463648 ] [ -0.785398 -2.35619 -2.35619 -0.785398 ]

----------------------------------------------------------------------Inverse Tangent Function in Degree double atand2(double y, double x) matrix atand2(double y, matrix x) matrix atand2(matrix y, double x) matrix atand2(matrix y, matrix x)----------------------------------------------------------------------

atand 2 ( y , x )=atan2 ( y , x ) 180π

−∞<x<∞ ,−∞< y<∞,−180<atand 2 ( y , x )≤180

#> atand2( 1, 1 ) ; // first quadrant, x = 1, y = 1 ans = 45

#> atand2( 1, -1 ); // second quadrant, x = -1, y = 1 ans = 135

#> atand2( -1, -1 ); // third quadrant, x = -1, y = -1 ans = -135

#> atand2( -1, 1 ); // fourth quadrant, x = 1, y = -1 ans = -45

For a pair of rows and columns with the same dimension, operation applies for a pair of elements (x i , y i)

#> atand2( [1,1,-1,-1], [1,-1,-1,1] ); ans = [ 45 135 -135 -45 ]

Otherwise, a structure similar to the Kronecker product is obtained

#> atand2( [1;0.5;-0.5;-1], [1,-1,-1,1] ); ans = [ 45 135 135 45 ] [ 26.5651 153.435 153.435 26.5651 ] [ -26.5651 -153.435 -153.435 -26.5651 ]

40

Page 41: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ -45 -135 -135 -45 ]

----------------------------------------------------------------------Inverse Hyperbolic Tangent Function double atanh(double x) complex atanh(complex z) matrix atanh(matrix A)----------------------------------------------------------------------

atanh (x )=12

log 1+x1−x

−1<x<1 ,−∞<atanh ( x )<∞

tanh−1 (x )=12

log 1+z1−z

#> atanh( 0.5 ); tanh(ans); ans = 0.54930614 ans = 0.5

#> atanh( 2i ); tanh(ans); ans = 5.55112e-017 + 1.10715! ans = 2.77556e-016 + 2!

#> atanh( [ 0.5, 2i ] ); tanh(ans); ans = [ 0.549306 5.55112e-017 + i 1.10715 ] ans = [ 0.5 2.77556e-016 + i 2 ]

#> plot.x( -0.99, 0.99 ) ( atanh(x) );

[ B ]

----------------------------------------------------------------------Beta Function double .B(double x, double y) // dot-only matrix .B(double x, matrix y) matrix .B(matrix x, double y)

41

Page 42: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

matrix .B(matrix x, matrix y)----------------------------------------------------------------------

B (x , y )=Γ ( x )Γ ( y)Γ (x+ y)

=∫0

1

t x−1 (1−t ) y−1dt

¿2∫0

π2

sin2x−1θ cos2 y−1θdθ

#> .B(3,4); ans = 0.016666667

#> (.G(3)*.G(4) )/.G(3+4); // from definition ans = 0.016666667

---------------------------------------------------------------------- matrix A.backsub ----------------------------------------------------------------------For an n×(n+1) matrix, backward substitution is carried out to find a solution vector.

[a11 a12 a13

0 a22 a23

0 0 a33] [ x1

x2

x3]=[b1

b2

b3]⇒ a11 x1+a12 x2+a13 x3 ¿ b1

a22 x2+a23 x3 ¿ b2

a33 x3 ¿ b3

x3=b3 / a33

x2=(b2−a23 x3 ) / a22

x1=(b1−a12 x2−a13 x3 ) / a11

#> A = [ 2,-4,-10,12; 0,-1,15,-16; 0,0,-134,134 ]; A = [ 2 -4 -10 12 ] [ 0 -1 15 -16 ] [ 0 0 -134 134 ]#> A.backsub; ans = [ 3 ] [ 1 ] [ -1 ]

---------------------------------------------------------------------- poly poly.binom(double n)----------------------------------------------------------------------binomial polynomial of degree n

42

Page 43: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

(xn)= 1n !x ( x−1 ) ( x−2 )×…× ( x−n−2 )(x−n−1)

#> for.n(0,5) poly.binom(n).ratio; ans = (1/1) * poly( 1 )

ans = (1/1) * poly( 0 1 ) ans = (1/2) * poly( 0 -1 1 ) ans = (1/6) * poly( 0 2 -3 1 ) ans = (1/24) * poly( 0 -6 11 -6 1 ) ans = (1/120) * poly( 0 24 -50 35 -10 1 )

#> .hold; for.n(1,6) plot.x(0,n) ( poly.binom(n+1)(x) ); plot;

---------------------------------------------------------------------- double .bisect(double a,double b,double f(double x)) // dot-only----------------------------------------------------------------------In finding a root of f ( x )=0, it may happen that the given object function f (x) is not simple. Then, it is recommended to define an objective function 'f(x)' and combine with the dot-only function installed in Cemmath. For a simple case, a root of ex=5 can be found by

#> double fun(x) = exp(x)-5;#> .bisect(0,3, fun); // dot function in Cemmath ans = 1.6094379

Another example is to find s in the following equation

∫0

s

x sin (x )dx=0

If the Umbrella 'int' is utilized, solution can be found by

#> double fn(s) = int.x(0,s) ( x*sin(x) );#> .bisect(pi,2*pi, fn);

43

Page 44: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

ans = 4.4934094

Similarly in the shooting method for ordinary differential equations, solution is frequently found by the dot function '.bisect(a,b,f(x))' . For example, the following system

y ' '+2 x y '=0y (0 )=2 , y (1 )=3}yex=2+ erf (x )

erf (1)

can be solved alternatively by assuming a slope atx=0 and satisfying the objective function y (1 )=3. The exact slope is known to be

y ' ( 0 )= 1erf (1 ) [ 2

√πe−x2]

x=0

= 2√π erf (1)

=1.33900⋯

An example run is shown below.

double fn(s) { y1 = ode.x(0,1) ( y'' = -2*x*y', y = 2, y' = s ).return(y).end; return y1-3;}#> .bisect(1,3, fn); ans = 1.3390033

//----------------------This function can be written by users as followsdouble user_bisect(a,b, fun(x)) { eps = 1.e-6; ya = fun(a); if( |ya| < eps ) return a; yb = fun(b); if( |yb| < eps ) return b; if( ya*yb > 0 ) { "y(a)y(b) > 0"; return NaN; }

iter = 0; while(1) { if( ++iter > 200 ) { "bisection failed"; return NaN; } x = 0.5*(a+b); y = fun(x); [ iter,a,b,x,y ];; // display with double semicolons ;;

if( |y| > inf ) { "bisection diverged"; return NaN; } if( |a-b|/(1.+|a|+|b|) < eps || |y| < eps ) break;

if( ya*y > 0 ) a = x;

44

Page 45: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

else b = x; } return x;}#> user_bisect(1,3, fn); ans = [ 1 1 3 2 0.493648 ] ans = [ 2 1 2 1.5 0.120236 ] ans = [ 3 1 1.5 1.25 -0.0664698 ] ans = [ 4 1.25 1.5 1.375 0.0268832 ] ans = [ 5 1.25 1.375 1.3125 -0.0197933 ] ans = [ 6 1.3125 1.375 1.34375 0.00354493 ] ans = [ 7 1.3125 1.34375 1.32813 -0.0081242 ] ans = [ 8 1.32813 1.34375 1.33594 -0.00228964 ] ans = [ 9 1.33594 1.34375 1.33984 0.000627647 ] ans = [10 1.33594 1.33984 1.33789 -0.000830994 ] ans = [11 1.33789 1.33984 1.33887 -0.000101674 ] ans = [12 1.33887 1.33984 1.33936 0.000262986 ] ans = [13 1.33887 1.33936 1.33911 8.06564e-005 ] ans = [14 1.33887 1.33911 1.33899 -1.05087e-005 ] ans = [15 1.33899 1.33911 1.33905 3.50738e-005 ] ans = [16 1.33899 1.33905 1.33902 1.22826e-005 ] ans = [17 1.33899 1.33902 1.339 8.86954e-007 ] ans = 1.3390045

[ C ]

----------------------------------------------------------------------Cubic Root Function double cbrt (double x) complex cbrt (complex z) matrix cbrt (matrix A) ----------------------------------------------------------------------#> cbrt( 8 ); ans = 2

#> cbrt( 1i ); ans = 0.866025 + 0.5!

#> cbrt( [ 8, 1i ] ); ans = [ 2 0.866025 + i 0.5 ]

---------------------------------------------------------------------- double .ceil (double x)

matrix .ceil (matrix A)----------------------------------------------------------------------Integer near ∞

45

Page 46: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> .ceil(pi); ans = 4

#> .ceil( [ pi, -pi ] ); ans = [ 4 -3 ]

---------------------------------------------------------------------- double x.ceil----------------------------------------------------------------------Integer near ∞

#> pi.ceil; ans = 4

#> (-pi).ceil; // dot(.) is prior to unary minus ans = -3

#> -pi.ceil; ans = -4

---------------------------------------------------------------------- matrix A.chol----------------------------------------------------------------------Choleski decomposition

A=UTU

a ij=∑k=1

i−1

ukiuki+uii uii⇒uii=(a ii−∑

k=1

i−1

ukiuki )1 / 2

a ij=∑k=1

i−1

ukiukj+u iiuij⇒uij=( aij−∑

k=1

i−1

ukiukj )/uii

where j=i+1, i+2 ,…,n−1 ,n.

#> A = [ 2,-1,1; -1,3,-2; 1,-2,5 ]; A = [ 2 -1 1 ] [ -1 3 -2 ] [ 1 -2 5 ]#> A.chol; ans = [ 1.41421 -0.707107 0.707107 ] [ 0 1.58114 -0.948683 ] [ 0 0 1.89737 ]

46

Page 47: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

For users convenience, a direct code is presented below.

void user_chol(matrix& A) { n = A.m; U = .zeros(n);

for.i(1,n) { sum = A(i,i) - U..(1:i-1)(i).norm22; if( sum < 0 ) { "negative diagonal in Choleski";; break; }

U(i,i) = sqrt(sum); for.j(i+1,n) U(i,j) = (A(i,j) - U..(1:i-1)(i) ** U..(1:i-1)(j))/U(i,i); U ;; // display U..(i)(i:n) }}

#> user_chol(A); // user function listed above user_chol.U = [ 1.41421 -0.707107 0.707107 ] [ 0 0 0 ] [ 0 0 0 ] user_chol.U = [ 1.41421 -0.707107 0.707107 ] [ 0 1.58114 -0.948683 ] [ 0 0 0 ] user_chol.U = [ 1.41421 -0.707107 0.707107 ] [ 0 1.58114 -0.948683 ] [ 0 0 1.89737 ]

---------------------------------------------------------------------- double Cint(double x) matrix Cint(matrix x) ----------------------------------------------------------------------

Cint ( x )=1x∫0

x 1−cos tt 2 dt

#> Cint(1); ans = 0.48638538

#> Cint([1,2]); ans = [ 0.486385 0.44867 ]

---------------------------------------------------------------------- matrix A.circle ----------------------------------------------------------------------An equation of a circle passing three points is created by

47

Page 48: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ x1,y1, x2,y2, x3,y3 ].circle;

and is represented as

A (x2+ y2 )+Bx+Cy+D=0

The coefficients are expressed by [ A, B, C, D ]

#> [ 1,1, -1,2, 2,4 ].circle; circle (-7)(x^2+y^2) + (9)x + (39)y + (-34) = 0 center = ( 0.642857, 2.78571 ) radius = 1.82108 ans = [ -7 9 39 -34 ]

---------------------------------------------------------------------- matrix W.col(double j) // equivalent to W(*,j)----------------------------------------------------------------------j-th column vector, both read/write

Note that this function allows to modify the original matrix.

#> A = (1:12)._4 ; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.col(3); ans = [ 7 ] [ 8 ] [ 9 ]

#> A.col(3) += 100;

A = [ 1 4 107 10 ] [ 2 5 108 11 ] [ 3 6 109 12 ]

---------------------------------------------------------------------- matrix A.colabs ----------------------------------------------------------------------finds Euclidean norm of each columnnote: Each column can be normalized by A.unit

48

Page 49: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A = [ 1,-3; -2,4 ]; A = [ 1 -3 ] [ -2 4 ]

#> A.colabs; // [ sqrt(1+4), sqrt(9+16) ] ans = [ 2.23607 5 ]

#> A().colabs; ans = [ 1 2 3 4 ]

---------------------------------------------------------------------- matrix A.coldel(double j) ----------------------------------------------------------------------deletes j-th column

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]#> A.coldel(3); ans = [ 1 4 10 ] [ 2 5 11 ] [ 3 6 12 ]

Note that the original matrix is not changed. To modify a matrix itself, assignment should be carried out

#> A.col(3) = []; // equivalent to A = A.coldel(3); A = [ 1 4 10 ] [ 2 5 11 ] [ 3 6 12 ]

---------------------------------------------------------------------- matrix A.coldet(double j) ----------------------------------------------------------------------j-th column determinantConsider the Laplace expansion of a determinant

49

Page 50: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

det (A )=|a11 a12 a13 a14

a21 a22 a23 a24

a31 a32 a33 a34

a41 a42 a43 a44|

det (A )=∑i=1

n

C ija ij=∑j=1

n

Cij aij ,C ij=(−1 )i+ jdet ( Aij )

where Aij is a minor of A. Then, det (A ij ) is obtained by A.coldet(j).For example, an equation of a circle passing three points

(x¿¿1 , y1), (x¿¿2 , y2) ,(x¿¿3 , y3)¿¿¿is given as

det (A )=|x2+ y2 x1

2+ y12 x2

2+ y22 x3

2+ y32

x x1 x2 x3

y y1 y2 y3

1 1 1 1|

¿C 11( x2+ y2 )+C21 ( x )+C31 ( y )+C41 (1 )=0

For three points (1,1 ) , (−1,2 ) ,(2,4), we have

#> A = [ 1, 1+1,1+4,4+16; 1, 1,-1,2;1, 1,2,4;1, 1,1,1 ]; A = [ 1 2 5 20 ] [ 1 1 -1 2 ] [ 1 1 2 4 ] [ 1 1 1 1 ]

#> A.minor(1,1).det; ans = -7#> A.minor(2,1).det; ans = -9#> A.minor(3,1).det; ans = 39#> A.minor(4,1).det; ans = 34#> A.coldet(1); ans = [ -7 ] [ -9 ] [ 39 ] [ 34 ]

Therefore,

50

Page 51: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

(−1 )1+1 (−7 ) (x2+ y2 )−(−9 ) ( x )+(39 ) ( y )−(34) (1 )=0

#> [ 1,1, -1,2, 2,4 ].circle; // an easier approach circle (-7)(x^2+y^2) + (9)x + (39)y + (-34) = 0 center = ( 0.642857, 2.78571 ) radius = 1.82108 ans = [ -7 9 39 -34 ]

---------------------------------------------------------------------- matrix A.colend // equivalent to A(*,end), A.endcol----------------------------------------------------------------------returns an end column

#> A = [ 2,1,4; -1,3,2; 0,1,2 ]; A = [ 2 1 4 ] [ -1 3 2 ] [ 0 1 2 ]#> A.endcol; ans = [ 4 ] [ 2 ] [ 2 ]

---------------------------------------------------------------------- matrix A.colins(double j, matrix B)----------------------------------------------------------------------insert B at j-th column of A

Note that if j>A .n, horizontal concatenation A∨B is carried out.

#> A = (1:16)._4;A =[ 1 5 9 13 ][ 2 6 10 14 ][ 3 7 11 15 ][ 4 8 12 16 ]

#> A.inscol(1, [101:105; 201:205]); // starts at column 1ans =[ 101 102 103 104 105 1 5 9 13 ][ 201 202 203 204 205 2 6 10 14 ][ 0 0 0 0 0 3 7 11 15 ][ 0 0 0 0 0 4 8 12 16 ]

51

Page 52: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.inscol(2, [101:105; 201:205]'); // column 2ans =[ 1 101 201 5 9 13 ][ 2 102 202 6 10 14 ][ 3 103 203 7 11 15 ][ 4 104 204 8 12 16 ][ 0 105 205 0 0 0 ]

#> A.inscol(100, [101:105; 201:205]'); // out of range makes attachingans =[ 1 5 9 13 101 201 ][ 2 6 10 14 102 202 ][ 3 7 11 15 103 203 ][ 4 8 12 16 104 204 ][ 0 0 0 0 105 205 ]

---------------------------------------------------------------------- matrix A.colskip(double k)----------------------------------------------------------------------if k>0, 1,1+k ,1+2k ,⋯ else ⋯ , n−3k ,n−2k ,n−k , n

under develpment

---------------------------------------------------------------------- matrix A.colswap(double i, double j)----------------------------------------------------------------------swap i-th and j-th columns

#> A = [ 1,2,3,4; 5,6,7,8 ]; A = [ 1 2 3 4 ] [ 5 6 7 8 ]

#> A.colswap(2,4); ans = [ 1 4 3 2 ] [ 5 8 7 6 ]

---------------------------------------------------------------------- matrix p.compan ----------------------------------------------------------------------A companion matrix of a polynomial

p ( x )=xn+an−1 xn−1+an−2 x

n−2+…+a1 x+a0

52

Page 53: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

is determined by using its coefficients to be

A=[−an−1 −an−2 ⋯ −a1 −a0

1 0 0 ⋯ 00 1 0 ⋯ ⋯⋯ ⋯ ⋱ ⋱ 00 0 ⋯ 1 0

]%> companion matrix #> p = .[ 1, -10, 23, 6 ]; p = poly( 6 23 -10 1 ) = x^3 -10x^2 +23x +6

#> A = p .compan;ans =

[ 10 -23 -6 ] [ 1 0 0 ] [ 0 1 0 ] #> A .eigpoly;

ans = poly( 6 23 -10 1 ) = x^3 -10x^2 +23x +6

---------------------------------------------------------------------- double A.cond ----------------------------------------------------------------------condition number, A.norminf*A.inv.norminf

|| A | |∞=max1≤ i≤ n

∑j=1

n

|aij | , cond (A)=|| A | |∞ ||A−1 | |∞

#> A = [ 1, 3; 2, 5 ]; A = [ 1 3 ] [ 2 5 ]

#> A.cond ; A.norminf * A.inv.norminf; ans = 56 ans = 56

#> A.norminf; ans = 7#> A.inv; A.inv.norminf; ans = [ -5 3 ]

53

Page 54: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 2 -1 ] ans = 8

---------------------------------------------------------------------- matrix A.conj // equivalent to ~A = A.conj----------------------------------------------------------------------complex conjugate

A=[a1 a4 a7 a10

a2 a5 a8 a11

a3 a6 a9 a12] , A=A .conj=[a1 a4 a7 a10

a2 a5 a8 a11

a3 a6 a9 a12]

#> A = [ 1+1i, 2-3i; 5-4i, 3+1i; 2+3i, -1+5i ]; A = [ 1 + i 1 2 - i 3 ] [ 5 - i 4 3 + i 1 ] [ 2 + i 3 -1 + i 5 ]

#> ~A; // ~A = A.conj ans = [ 1 - i 1 2 + i 3 ] [ 5 + i 4 3 - i 1 ] [ 2 - i 3 -1 - i 5 ]

---------------------------------------------------------------------- matrix A.conjtr // equivalent to A' = A.conjtr----------------------------------------------------------------------conjugate transpose

A=[a1 a4 a7 a10

a2 a5 a8 a11

a3 a6 a9 a12] , A '=A .conjtr=[ a1 a2 a3

a4 a5 a6

a7 a8 a9

a10 a11 a12]

#> A = [ 1+1i, 2-3i; 5-4i, 3+1i; 2+3i, -1+5i ]; A = [ 1 + i 1 2 - i 3 ] [ 5 - i 4 3 + i 1 ] [ 2 + i 3 -1 + i 5 ]

#> A'; // A' = A.conjtr ans = [ 1 - i 1 5 + i 4 2 - i 3 ] [ 2 + i 3 3 - i 1 -1 - i 5 ]

54

Page 55: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.'; // compare with A.' = A.tr ans = [ 1 - i 1 5 + i 4 2 - i 3 ] [ 2 + i 3 3 - i 1 -1 - i 5 ]

---------------------------------------------------------------------- double .corrcoff(matrix A, matrix B) ----------------------------------------------------------------------correlation coefficient

#> x = [ 1,2,3,4 ]; y = [ 2,3,5,9 ]; x = [ 1 2 3 4 ] y = [ 2 3 5 9 ]

#> p = .polyfit(x,y,1); p = poly( -1 2.3 ) = 2.3x -1

#> .corrcoef( y,p(x) ); // correlation between data and fitting ans = 0.9591663

#> plot.x(1,4) ( p(x) ); plot+(x,y);

----------------------------------------------------------------------Cosine Function double cos(double x) complex cos(complex z) matrix cos(matrix A)----------------------------------------------------------------------

cos ( x+2π )=cos ( x ) ,cos (ix )=cosh (x)−∞<x<∞ ,−1≤ cos ( x )≤1

cos ( x+iy )=cos x cosh y−i sin x sinh y#> cos( pi/3 ); ans = 0.5

#> cos( 1+2! ); ans = 2.03272 - 3.0519!

55

Page 56: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> cos( [ pi/3, 1+2i ] ); ans = [ 0.5 2.03272 - i 3.0519 ]

#> plot.x( 0,pi ) ( cos(x) );

----------------------------------------------------------------------Cosine Function in Degree double cosd(double x) complex cosd(complex z) matrix cosd(matrix A)----------------------------------------------------------------------

cosd ( x )=cos ( πx180 ) , cosd (x+360 )=cosd (x )

−∞<x<∞ ,−1≤cosd (x )≤1

#> cosd( 60 ); ans = 0.5

#> cosd( 1.todeg+2.todeg! ); ans = 2.03272 - 3.0519!

#> cosd( [ 60, 1.todeg+2.todeg! ] ); ans = [ 0.5 2.03272 - i 3.0519 ]

#> plot.x( 0,180 ) ( cosd(x) );

----------------------------------------------------------------------Hyperbolic Cosine Function

56

Page 57: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

double cosh(double x) complex cosh(complex z) matrix cosh(matrix A)----------------------------------------------------------------------

cosh ( x )= ex+e−x

2, cosh (ix )=cos (x )

−∞<x<∞ ,1≤ cosh ( x )<∞cosh ( x+iy )=cosh xcos y+i sinh x sin y

#> cosh( 1 ); ans = 1.5430806

#> cosh( 2i ); ans = -0.416147 + 0!

#> cosh( [ 1, 2i ] ); ans = [ 1.54308 -0.416147 ]

#> plot.x( -5,5 ) ( cosh(x) );

----------------------------------------------------------------------Cotangent Function double cot(double x) complex cot(complex z) matrix cot(matrix A)----------------------------------------------------------------------

cot ( x )= 1tan ( x )

,cot ( x+π )=cot (x)

−π2

<x<0 ,0<x< π2,−∞<cot (x )<∞

#> cot( pi/4 ); ans = 1

#> cot( 2i );

57

Page 58: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

ans = 0 - 1.03731!

#> cot( [ pi/4, 2i ] ); ans = [ 1 0 - i 1.03731 ]

#> plot.x( -pi/2+0.01,-0.01 )( cot(x) ); #> plot+.x( 0.01,pi/2-0.01 )( cot(x) );

----------------------------------------------------------------------Cotangent Function in Degree double cotd(double x) complex cotd(complex z) matrix cotd(matrix A)----------------------------------------------------------------------

cotd ( x )=cot( πx180 )−90<x<0 ,0<x<90 ,−∞<cotd ( x )<∞

#> cotd( 45 ); ans = 1

#> cotd( 2.todeg! ); ans = 0 - 1.03731!

#> cotd( [ 45, 2.todeg! ] ); ans = [ 1 0 - i 1.03731 ]

#> plot.x( -89,-1 )( cotd(x) ); #> plot+.x( 1,89 )( cotd(x) );

58

Page 59: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------Hyperbolic Cotangent Function double coth(double x) complex coth(complex z) matrix coth(matrix A)----------------------------------------------------------------------

coth ( x )= 1tanh ( x )

−∞<x<∞ ,coth (x )←1 ,1<coth ( x )

#> coth( 1 ); ans = 1.3130353

#> coth( 2i ); ans = 0 + 0.457658!

#> coth( [ 1, 2i ] ); ans = [ 1.31304 0 + i 0.457658 ]

#> plot.x( -5,-0.1 )( coth(x) ); #> plot+.x( 0.1,5 )( coth(x) );

---------------------------------------------------------------------- double .cross(matrix A, matrix B) ----------------------------------------------------------------------cross product

| i j kA1 A2 A3

B1 B2 B3|=i ( A2B3−A3B2 )+ j ( A3B1−A1B3 )+k (A1B2−A2B1)

#> .cross( [2,1,5], [-1,2,4] ) ; ans = [ -6 -13 5 ]

#> .cross( [2,1], [-1,2] ) ; ans = [ 0 -0 5 ]

59

Page 60: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------Cosecant Function double csc(double x) complex csc(complex z) matrix csc(matrix A)----------------------------------------------------------------------

csc ( x )= 1sin ( x )

, csc ( x+2π )=csc (x)

−∞<x<∞ ,csc (x )≤−1 ,1≤csc ( x )

#> csc( pi/6 ); ans = 2

#> csc( 2i ); ans = 0 - 0.275721!

#> csc( [ pi/6, 2i ] ); ans = [ 2 0 - i 0.275721 ]

#> plot.x( -pi/2+0.01, -0.01 )( csc(x) ); #> plot+.x( 0.01, pi/2-0.01 )( csc(x) );

----------------------------------------------------------------------Cosecant Function in Degree double cscd(double x) complex cscd(complex z) matrix cscd(matrix A)----------------------------------------------------------------------

cscd ( x )=csc( πx180 ) , cscd ( x+360 )=cscd (x )

−∞<x<∞ ,cscd ( x )≤−1 ,1≤cscd ( x )

#> cscd( 30 ); ans = 2

#> cscd( 2.todeg! );

60

Page 61: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

ans = 0 - 0.275721!

#> cscd( [ 30, 2.todeg! ] ); ans = [ 2 0 - i 0.275721 ]

#> plot.x( -90+1, -1 )( cscd(x) ); #> plot+.x( 1, 90-1 )( cscd(x) );

----------------------------------------------------------------------Hyperbolic Cosecant Function double csch(double x) complex csch(complex z) matrix csch(matrix A)----------------------------------------------------------------------

csch (x )= 1sinh ( x )

−∞<x<∞ ,−∞<csch ( x )<∞

#> csch( 0.5 ); ans = 1.9190348

#> csch( 2i ); ans = -0 - 1.09975!

#> csch( [ 0.5, 2i ] ); ans = [ 1.91903 -0 - i 1.09975 ]

#> plot.x( -5,-0.1)( csch(x) ); #> plot+.x( 0.1,5 )( csch(x) );

61

Page 62: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- matrix A.cumprod // column-first operation----------------------------------------------------------------------cumulative product along each column

#> A = [ 1,3,2; 5,4,3; 6,7,4 ]; A = [ 1 3 2 ] [ 5 4 3 ] [ 6 7 4 ]

#> A.cumprod; // multi-rows (column-first) ans = [ 1 3 2 ] [ 5 12 6 ] [ 30 84 24 ]

#> A().cumprod; // a single row ans = [ 1 5 30 90 360 2520 5040 15120 60480 ]

---------------------------------------------------------------------- matrix A.cumsum // column-first operation----------------------------------------------------------------------A~ = A.cumsum, cumulative sum

#> A = [ 1,3,2; 5,4,3; 6,7,4 ]; A = [ 1 3 2 ] [ 5 4 3 ] [ 6 7 4 ]

#> A~; // multi-rows (column-first), equivalent to A~ = A.cumsum ans = [ 1 3 2 ] [ 6 7 5 ] [ 12 14 9 ]

#> A()~; // a single row ans = [ 1 6 12 15 19 26 28 31 35 ]

#> A~~; // the same as A.cumsum.cumsum

ans = [ 1 3 2 ] [ 7 10 7 ] [ 19 24 16 ]

----------------------------------------------------------------------

62

Page 63: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

poly p.cumsum ----------------------------------------------------------------------∑ p=p . =p . cumsum ,cumulative sum

p . cumsum= p . =∑ p (x )= p (1 )+ p (2 )+ p (3 )+…+ p(n)

#> p = .[1].up(3); // x^3 p = poly( 0 0 0 1 ) = x^3

#> p.~; // Σ k3=(1 / 4 )n2 (n+1 )2ans = poly( 0 0 0.25 0.5 0.25 )

= 0.25x^4 +0.5x^3 +0.25x^2

---------------------------------------------------------------------- matrix cumtrapz(matrix x,matrix y) ----------------------------------------------------------------------area by the trapezodial rule

12¿

⋯+(xn−xn−1 ) ( yn−1+ yn )¿

#> x = 0:0.25:1;; y=1 ./(1+x.^2);; cumtrapz(x,y); ans = [ 0 0.242647 0.460294 0.640294 0.782794 ]

#> int.x[5](0,1) ( 1/(1+x^2) ).poly(1).return; ans = [ 0 ] [ 0.242647 ] [ 0.460294 ] [ 0.640294 ] [ 0.782794 ]

---------------------------------------------------------------------- complex z.cyl ----------------------------------------------------------------------convert a complex number from cylindrical to rectangular coordinates

#> z = 1 + pi!/6; z = 1 + 0.523599!

#> z.cyl; ans = 0.866025 + 0.5!

63

Page 64: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- vertex v.cyl ----------------------------------------------------------------------read in cylindrical coordinate

#> < 1,1,1 > .cyl ; // r = sqrt(x^2+y^2) ans = < 1.414 0.7854 1 >

---------------------------------------------------------------------- csys csys.cyl ----------------------------------------------------------------------a cylindrical coordinate system

#> cs1 = csys.cyl; cs1 = 'cyl' local csys org = < 0 0 0 > dir = [ 1 0 0 ] [ 0 1 0 ] [ 0 0 1 ]

#> < 1,sqrt(3) >.cs1; ans = < 2 1.047 0 >

---------------------------------------------------------------------- double .decimal (double x) matrix .decimal (matrix A) ----------------------------------------------------------------------

x=x .round+x .decimal

#> .decimal(pi); ans = 0.14159265

#> .decimal( [pi, _e] ); ans = [ 0.141593 -0.281718 ]

---------------------------------------------------------------------- double x.decimal matrix A.decimal poly p.decimal----------------------------------------------------------------------deviation from the closest integer

Note that x = x.round + x.decimal

For a matrix and a polynomial, element-by-element operation is applied.

64

Page 65: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> pi.decimal; ans = 0.14159265

#> (-pi).decimal; ans = -0.14159265

---------------------------------------------------------------------- double z.deg // both read/write ----------------------------------------------------------------------z.r |z| = sqrt(x*x+y*y)z.t arg = atan(y/x)z.deg deg = atan(y/x)*180/pi

#> z = 3+4!; z = 3 + 4!

#> z.deg; // read ans = 53.130102

#> z.deg = 90; z; // writeans = 90z = 3.06152e-016 + 5!

---------------------------------------------------------------------- void csys.deg void csys.rad ----------------------------------------------------------------------angles in the degree system

#> csys.deg; < 1, 45, 0, cyl > ; ans = < 0.7071 0.7071 0 >

In the above, 360 degree system is activated by "csys.deg". Therefore, writing a vertex in a cylindrical coordinate system by ¿ r , θ , z , cyl>¿ interprets θ to be an angle in degree system. Thus we have

x=r cosθ=(1 ) cos45O=(1 ) cos π4= 1

√2

y=rsin θ=(1 ) sin 45O=(1 )sin π4= 1

√2

#> csys.rad; < 1, pi/4, 0, cyl > ; ans = < 0.7071 0.7071 0 >

65

Page 66: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

The default system is the radian coordinate system.

[ D ]

---------------------------------------------------------------------- vertex .del(double f(x,y,z)) (double a, double b, double c) dot-only----------------------------------------------------------------------For a given point

(a ,b , c ), the gradient ∇ f

is numerically calculated from the

following syntax

∇ f=i ∂ f∂x

+ j ∂ f∂ y

+k ∂ f∂ z

∇ f=er∂ f∂ r

+eθ1r∂ f∂θ

+ez∂ f∂ z

∇ f=er∂ f∂ r

+eφ1r∂ f∂φ

+eθ1

r sinφ∂ f∂θ

.del ( f(x,y,z) ) (a,b,c).del ( f(x,y,z) ) (a,b,c).cyl.del ( f(x,y,z) ) (a,b,c).sph

#> .del( x^3*y^2*z )( 2,3,4 ) ; #> .del( x^3*y^2*z )( 3,pi/3,4 ) .cyl; #> .del( x^3*y^2*z )( 3,pi/4,pi/3 ) .sph;

ans = < 432 192 72 >ans = < 118.4 75.4 29.61 >ans = < 17.44 14.8 7.851 >

---------------------------------------------------------------------- double .del*(u,v,w) (double a, double b, double c) dot-only----------------------------------------------------------------------The divergence of a vector field u=(u , v ,w) is defined as

∇⋅ u=∂u∂ x

+ ∂v∂ y

+ ∂w∂z

∇⋅ u=1r∂∂ r

(r u )+1r∂ v∂θ

+ ∂w∂ z

66

Page 67: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

∇⋅ u= 1r2

∂∂ r

(r2u )+ 1r sinφ

∂∂φ

(sinφv )+ 1r sinφ

∂w∂θ

.del * ( u(x,y,z),v(x,y,z),w(x,y,z) ) (a,b,c)

.del * ( u(x,y,z),v(x,y,z),w(x,y,z) ) (a,b,c).cyl

.del * ( u(x,y,z),v(x,y,z),w(x,y,z) ) (a,b,c).sph

#> .del*( x*y^2*z, x*x*y, x*z*z ) (2,3,4); #> .del * ( x*y^2*z, x*x*y, x*z*z ) (3,pi/3,4).cyl; #> .del * ( x*y^2*z, x*x*y, x*z*z ) (3,pi/4,pi/3).sph;

ans = 56.0000800ans = 35.7731456ans = 10.2560429

---------------------------------------------------------------------- vertex .del^(u,v,w) (double a, double b, double c) dot-only----------------------------------------------------------------------The curl of a vector field u=(u , v ,w) is defined as

∇×u=| i j k∂∂x

∂∂ y

∂∂ z

u v w|

∇×u=1r| er r eθ ez

∂∂r

∂∂θ

∂∂ z

u rv w|

∇×u= 1r2 sinφ| er r eφ r sinφeθ

∂∂ r

∂∂φ

∂∂θ

u rv rw sinφ|.del ^ ( u(x,y,z),v(x,y,z),w(x,y,z) ) (a,b,c).del ^ ( u(x,y,z),v(x,y,z),w(x,y,z) ) (a,b,c).cyl.del ^ ( u(x,y,z),v(x,y,z),w(x,y,z) ) (a,b,c).sph

#> .del ^ ( x*y^2*z, x*x*y, x*z*z ) (2,3,4); #> .del ^ ( x*y^2*z, x*x*y, x*z*z ) (3,pi/3,4).cyl;

67

Page 68: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> .del ^ ( x*y^2*z, x*x*y, x*z*z ) (3,pi/4,pi/3).sph;

ans = < 0 2 -36 >ans = < 0 -12.71 1.047 >ans = < 1.097 -1.321 5.424 >

---------------------------------------------------------------------- double .del2(double f(x,y,z)) (double a, double b, double c) dot-only ----------------------------------------------------------------------The Laplacian of a function f (x , y , z) is defined as

∇2 f= ∂2 f∂ x2 +

∂2 f∂ y2 +

∂2 f∂ z2

∇2 f=1r∂∂ r (r ∂ f∂r )+ 1

r2∂2 f∂θ2 +

∂2 f∂ z2

∇2 f= 1r2

∂∂r (r2 ∂ f

∂r )+ 1r2sinφ

∂∂φ (sinφ ∂ f

∂φ )+ 1r2sin 2φ

∂2 f∂θ2

.del2 ( f(x,y,z) ) (a,b,c)

.del2 ( f(x,y,z) ) (a,b,c).cyl

.del2 ( f(x,y,z) ) (a,b,c).sph

#> .del2 ( x^2*y^2*z^3 ) (2,3,4); #> .del2 ( x^2*y^2*z^3 ) (3,pi/3,4).cyl; #> .del2 ( x^2*y^2*z^3 ) (3,pi/4,pi/3).sph;

ans = 2528.0051988ans = 645.6077851ans = 16.1024906

---------------------------------------------------------------------- matrix .del[] .x1.x2. ... .xn(f)(double c1,c2,...,cn) dot-only ----------------------------------------------------------------------gradient

∇ f=e1∂ f∂ x1

+e2∂ f∂ x2

+…+en∂ f∂ xn

.del[] .x1.x2 .xn ( f(x1,x2, …,xn) ) (c1,c2, …, cn)

f=x13 x2

2 x3 x42

68

Page 69: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

∇ f=e1 3 x12 x2

2x3 x42+e2 x1

32 x2 x3 x42+e3 x1

3 x22 x4

2+e4 x13x2

2x3 2x4

#> .del[] .x1.x2.x3.x4 ( x1^3*x2^2*x3*x4^2 ) (2,3,4,5); ans = [ 10800 4800 1800 2880 ]

---------------------------------------------------------------------- matrix .del[][].x1.x2. ... .xn(f1,f2,...,fm)(c1,c2,...,cn) dot-only ----------------------------------------------------------------------jacobian

J=[ ∂ f i∂x j ]=|∂ f 1

∂ x1

∂ f 1

∂x2⋯

∂ f 1

∂ xn∂ f 2

∂ x1

∂ f 2

∂x2⋯

∂ f 2

∂ xn⋮ ⋮ ⋱ ⋮∂ f m∂ x1

∂ f m∂x2

⋯∂ f m∂ xn

|.del[][] .x1.x2 .xn ( f1,f2,f3, … , fm ) (c1,c2, …, cn)

The operator ‘.del[][]’ plays a simple role of differentiation only, as similar to the operator ‘.del[]’.

Consider a vector function of f=(x2 y , x+3 y ,e x ( y+1 ) ) , and find a

Jacobian matrix at point r=(2,3). This can be solved by

#> .del[][] .x.y ( x*x*y, x+3*y, exp(x)*(y+1) )(2,3); ans =

[ 12 4 ] [ 1 3 ] [ 29.557 7.3891 ]

Therefore, we get a Jacobian matrix at point (2,3)r

J=[ ∂ f i∂x j ]=[ 12 41 3

29.557 7.3891]69

Page 70: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- poly p.denom(double nmax=10000) ----------------------------------------------------------------------returns an integer denominator up to an integer "nmax"

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

nmax = 10000 is used when a value of nmax is not specified. The least common multiplier (lcm) is found up to nmax.

#> poly( 1/2, 1/3, 1/4, 1/5 ).denom; ans = 60

#> poly( 1/2, 1/3, 1/4, 1/5 ).ratio; ans = (1/60) * poly( 30 20 15 12 )

---------------------------------------------------------------------- double A.det ----------------------------------------------------------------------determinant of a matrix

#> A = [ 3,4; 1,2 ]; A = [ 3 4 ] [ 1 2 ]

#> A.det; ans = 2

---------------------------------------------------------------------- double x.dfact matrix A.dfact poly p.dfact----------------------------------------------------------------------double factorial of x is defined to be x (x−2 ) ( x−4 ) ( x−6 )⋯

For a matrix and a polynomial, element-by-element dfact is applied.

if x is not an integer, the Gamma function is used when a factor becomes less than unity.

#> 8.dfact; // 8*6*4*2 ans = 384

#> 8.5 .dfact; ans = 550.84547

70

Page 71: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- matrix .diag(matrix A, double k=0) ----------------------------------------------------------------------#> .diag( [1,2,3,4] ); // [1,2,3,4].diagm(0), diagonal vectorans =[ 1 0 0 0 ][ 0 2 0 0 ][ 0 0 3 0 ][ 0 0 0 4 ]

#> .diag( [1,2], 1 ); // [1,2].diagm(1)ans =[ 0 1 0 ][ 0 0 2 ][ 0 0 0 ]

#> .diag( [3,4], -2 ); // [3,4].diagm(-2)ans =[ 0 0 0 0 ][ 0 0 0 0 ][ 3 0 0 0 ][ 0 4 0 0 ]

---------------------------------------------------------------------- matrix W.diag(double k) // both read/write----------------------------------------------------------------------diagonal vector

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.diag(0); ans = [ 1 ] [ 5 ] [ 9 ]#> A.diag(1); ans = [ 4 ] [ 8 ] [ 12 ]#> A.diag(-1); ans = [ 2 ]

71

Page 72: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 6 ]

#> A.diag(0) = 0; // diagonal vector is modified A = [ 0 4 7 10 ] [ 2 0 8 11 ] [ 3 6 0 12 ]

---------------------------------------------------------------------- matrix .diagcat( ... ) matrix .blkdiag( ... ) ----------------------------------------------------------------------diagonal concatenation, the same as blkdiag in matlab

%> block-diagonal matrix #> .diagcat( 5,6,7,8 );ans =

[ 5 0 0 0 ] [ 0 6 0 0 ] [ 0 0 7 0 ] [ 0 0 0 8 ]

#> .diagcat ( [1,2], 5, [11,13; 12,14] ); ans =

[ 1 2 0 0 0 ] [ 0 0 5 0 0 ]

[ 0 0 0 11 13 ] [ 0 0 0 12 14 ]

#> .diagcat ( 2*.I(2), .ones(2) ); ans =

[ 2 0 0 0 ] [ 0 2 0 0 ] [ 0 0 1 1 ] [ 0 0 1 1 ]

---------------------------------------------------------------------- matrix A.diagm(double k) ----------------------------------------------------------------------.diag(A,k) for vectors, otherwise all-zero off-diagonals

#> (1:4).diagm(0); ans = [ 1 0 0 0 ] [ 0 2 0 0 ] [ 0 0 3 0 ] [ 0 0 0 4 ]

72

Page 73: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> (1:4).diagm(-1); ans = [ 0 0 0 0 0 ] [ 1 0 0 0 0 ] [ 0 2 0 0 0 ] [ 0 0 3 0 0 ] [ 0 0 0 4 0 ]

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.diagm(0); ans = [ 1 0 0 ] [ 0 5 0 ] [ 0 0 9 ]

---------------------------------------------------------------------- matrix A.diff // column-first operation----------------------------------------------------------------------A` = A.diff, finite-difference

// one-row case, [ 2-1, 5-2, 7-5 ] and reduce 1 column, column-first#> A` ; ans = [ 1 3 2 ]

// multi-rows case, [ 3-1, 0-2, 4-5, 9-7 ; ... ] // and reduce 1 row, column-first#> B` ; ans =[ 2 -2 -1 2 ][ -1 4 6 5 ]

#> B`` ; // becomes 1-row after 2 operationsans = [ -3 6 7 3 ]

#> B``` ; // differenced on row elements after 3 operationsans = [ 9 1 -4 ]

---------------------------------------------------------------------- poly p.diff ----------------------------------------------------------------------Δ p=p .'=p =p .diff , finite difference

73

Page 74: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

p .diff=p ( x )−p(x−1)

#> p = .[1].up(3); // x^3 p = poly( 0 0 0 1 ) = x^3

#> p`; // x^3 – (x-1)^3 = x^3 – (x^3 -3x^2 +3x -1) ans = poly( 1 -3 3 ) = 3x^2 -3x +1

---------------------------------------------------------------------- matrix cs.dir ----------------------------------------------------------------------#> cs1 = csys.rec ;cs1 = 'rec' local csys org = < 0 0 0 > dir = [ 1 0 0 ] [ 0 1 0 ] [ 0 0 1 ]

#> cs1.org ; // origin of a coordinate system ans = < 0 0 0 >

#> cs1.dir ; // direction cosines of a coordinate system ans = [ 1 0 0 ] [ 0 1 0 ] [ 0 0 1 ]

---------------------------------------------------------------------- double .div(double a, double b) dot-only matrix .div(double a, matrix b) matrix .div(matrix a, double b) matrix .div(matrix a, matrix b)----------------------------------------------------------------------quotient q in a=bq+r #> .div(13,5); ans = 2

---------------------------------------------------------------------- matrix .divisor(double n) ----------------------------------------------------------------------integer divisors of an integer n

74

Page 75: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> .divisor(10); ans = [ 1 2 5 10 ]

"complete number search"; // 6 -> [ 1,2,3,6 ] 1+2+3 = 6 !!!for.n(2,100000) { if( .divisor(n).sum1 == 2*n ) n;} n = 6 n = 28 n = 496 n = 8128

---------------------------------------------------------------------- double .dot(matrix A, matrix B) dot-only----------------------------------------------------------------------A ** B = .dot(A,B)dot product of two matrices. columnwise counting and no matching in dimension allowed. #> A = [ 1,2,3,4 ]; B = [ 5,6,7 ]; A = [ 1 2 3 4 ] B = [ 5 6 7 ]

#> .dot(A,B); // (1)(5) + (2)(6) + (3)(7) ans = 38

#> A**B; ans = 38

---------------------------------------------------------------------- poly A.dpoly ----------------------------------------------------------------------convert a matrix into a polynomial by descending order

#> A = (1:8)._3; A = [ 1 4 7 ] [ 2 5 8 ] [ 3 6 0 ]

#> A.dpoly; ans = poly( 0 8 7 6 5 4 3 2 1 ) = x^8 +2x^7 +3x^6 +4x^5 +5x^4 +6x^3 +7x^2 +8x

[ E ]

75

Page 76: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- double .E1/expint (double x) matrix .E1/expint (matrix A) ----------------------------------------------------------------------

E1 ( z )=∫z

∞ e−t

tdt=∫

1

∞ e− zt

tdt=−γ−ln z+z− z2

2 !2+ z3

3 !3+…+(−1 )n+1 zn

n !n+…

#> plot.x(0.2,1.6) ( 0, .E1(x) );

---------------------------------------------------------------------- double .Ei (double x) // dot only matrix .Ei (matrix A) ----------------------------------------------------------------------

Ei ( x>0 )=∫−∞

x e t

tdt=γ+ ln x+x+ x2

2!2+ x3

3!3+…+ xn

n !n+…

#> plot.x(0.2,1.6) ( 0, .Ei(x) );

---------------------------------------------------------------------- matrix .e_k(double n), double k dot-only----------------------------------------------------------------------k -th unit vector in an n-dimensional space

e1=(1,0,0 ,…,0)e2=(0,1,0 ,…,0)

76

Page 77: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

⋮en=(0,0,0 ,…,1)

#> k=2; .e_k(5);k = 2 ans = [ 0 1 0 0 0 ]

#> for.k(1,5) .e_k(5); ans = [ 1 0 0 0 0 ] ans = [ 0 1 0 0 0 ] ans = [ 0 0 1 0 0 ] ans = [ 0 0 0 1 0 ] ans = [ 0 0 0 0 1 ]

---------------------------------------------------------------------- matrix A.eig (matrix X, matrix D) = A.eig // tuple ----------------------------------------------------------------------return eigenvalues

With two l-values, modal matrix (eigenvectors) and spectral matrix (eigenvalues) are obtained.

#> A = [ -3,4; 5,-2 ]; A = [ -3 4 ] [ 5 -2 ]

#> A.eig; ans = [ 2 ] [ -7 ]

#> (X,D) = A.eig; X = [ 4 -5 ] [ 5 5 ] D = [ 2 0 ] [ 0 -7 ]

---------------------------------------------------------------------- double A.eiginvpow(double shift) (matrix lam, matrix x) = A.eiginvpow(double shift) // tuple ----------------------------------------------------------------------the absolute smallest eigenvalue by inverse power method

77

Page 78: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A = [ -3,4; 5,-2 ]; A = [ -3 4 ] [ 5 -2 ]

#> A.eiginvpow(0); ans = 1.9999999

#> (lam,x) = A.eiginvpow(0); lam = 1.9999999 x = [ 0.8 ] [ 1 ]

User code can be written as follows.(step 1) Set λ (0 )=0 , x ( 0)=1 , k=0(step 2) Solve A y (k +1)=x ( k ) to find y ( k+1) and λ (k+1 )

(step 3) Modify x (k +1)= 1λ( k+1 ) y

(k +1) with assumed eigenvalue λ (k+1 )

(step 4) Repeat steps 2-3 until convergence.

double eiginvpow(matrix A, &x) { // A is copied, x is referred, lam = k = 0 ; x = .ones(A.m,1);

while( 1 ) { lamo = lam; y = A \ x ; [ ++k, lam = y.maxentry , (x = y / lam )' ] ;; // to display if( lam .-. lamo < 1.e-6 ) break; // relative difference } return 1 / lam;}#> A = [ -3,4; 5,-2 ] ;; x = [] ;; // declare a matrix#> lam = eiginvpow(A,x);

k 1/lamba x(1) x(2) [ 1 0.571429 0.75 1 ] [ 2 0.482143 0.814815 1 ] [ 3 0.505291 0.795812 1 ] [ 4 0.498504 0.8012 1 ] [ 5 0.500429 0.799657 1 ] [ 6 0.499878 0.800098 1 ] [ 7 0.500035 0.799972 1 ] [ 8 0.49999 0.800008 1 ] [ 9 0.500003 0.799998 1 ] [ 10 0.499999 0.800001 1 ] [ 11 0.5 0.8 1 ]

----------------------------------------------------------------------

78

Page 79: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

poly A.eigpoly ----------------------------------------------------------------------eigenpolynomial of a matrix A

Fadeev-Leverrier method. det (A−λ I )=¿0¿

→− λn+c1 λn−1+⋯+cn−1 λ+cn=0

all the coefficients c i ,i=1,2,3 ,⋯ , n in the above can be determined recursively from the following relation

B1=A ,c1=trace B1

B2=A(B1−c1 I) , c2=12traceB2

Bi=A (Bi−1−c i−1 I ) , c i=1itraceB i, i=2,3 ,⋯ ,n

#> [ 3,2,4; 2,5; 1,-1,2 ] .eigpoly ; // unnamed matrix is used ans = poly( 6 23 -10 1 ) = x^3 -10x^2 +23x +6

By noting that cnλn

+cn−1

λn−1 +⋯+c2

λ2 +c1

λ−1=0

user code can be written as

poly user_eigpoly(matrix A) { // A is copied n = A.m; c = -poly(1:n+1); // to make c[0] = -1 B = A; c[1] = B.trace; for.k(2,n) { B = A*(B-c[k-1]*.I(n)) ;; // display c[k] = B.trace/k ; } return c.rev;} #> user_eigpoly( [ 3,2,4; 2,5; 1,-1,2 ] ); user_eigpoly.B = [ -13 -8 -20 ] [ -4 -21 8 ] [ -7 5 -12 ]

79

Page 80: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

user_eigpoly.B = [ -6 0 0 ] [ 0 -6 0 ] [ 0 0 -6 ] ans = poly( -6 -23 10 -1 ) = -x^3 +10x^2 -23x -6

---------------------------------------------------------------------- double A.eigpow(shift)

(double lam, matrix x) = A.eigpow(shift) // tuple ----------------------------------------------------------------------the absolute largest eigenvalue by the power method

#> A = [-3,6; 2,-2]; A = [ -3 6 ] [ 2 -2 ]

#> A.eigpow(0); // A.eigpow(shift) ans = -6

#> (lam,x) = A.eigpow(0); lam = -6 x = [ 1 ] [ -0.5 ]

User code can be written as follows.(step 1) Set λ (0 )=0 , x ( 0)=1 , k=0(step 2) Compute y ( k+1)=A x ( k ), and search the maximum absolute element y i from y ( k+1). Then, put λ (k+1 )= yi.

(step 3) Determine x (k +1)= 1λ( k+1 ) y

(k +1)

(step 4) repeat until convergence

double eigpow(matrix A, &x) { // A is copied, x is referred, lam = k = 0 ; x = .ones(A.m,1);

while( 1 ) { lamo = lam; y = A * x ; [ ++k, lam = y.maxentry , (x = y / lam )' ] ;; // to display if( lam ~= lamo ) break; // 6 digits identical } return lam;}#> A = [ -3,6; 2,-2 ];; x = [];; // declare a matrix x

80

Page 81: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> eigpow(A,x);

k lam x(1) x(2)[ 1 3 1 0 ]

[ 2 -3 1 -0.666667 ] [ 3 -7 1 -0.47619 ] [ 4 -5.85714 1 -0.504065 ] [ 5 -6.02439 1 -0.499325 ] [ 6 -5.99595 1 -0.500113 ] [ 7 -6.00068 1 -0.499981 ][ 8 -5.99989 1 -0.500003 ]

[ 9 -6.00002 1 -0.499999 ] [ 10 -6 1 -0.5 ]

---------------------------------------------------------------------- matrix A.eigvec(lam) ----------------------------------------------------------------------eigenvecter corresponding to an eigenvalue lam

#> A = [ 3,2,4; 2,5; 1,-1,2 ];; // lam = 6#> A.eigvec(6); ans = [ 4 ] [ 8 ] [ -1 ]

#> A = [ -2,0,1; 1,-3,1; 0,0,-3 ];#> A.eigvec(-3); ans = [ 0 1 ] [ 1 0 ] [ 0 -1 ]

#> A = [ 0,1; 3,0,1; 2 ] ;#> A.eigvec(-1); ans = [ 0.5 ] [ -0.5 ] [ -1 ]

#> A = [ 1, -2; 4, -3 ];;#> A .eigvec( -1+2i ); // case of complex eigenvalueans = [ -0.5 - i 0.5 ] [ -1 ]

---------------------------------------------------------------------- double A.end ----------------------------------------------------------------------

81

Page 82: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

real part of A(end,end)

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]#> A.end ans = 12

---------------------------------------------------------------------- matrix W.entry(matrix ind) // equivalent to W.(matrix)----------------------------------------------------------------------entry of elements,

#> A = (1:12)._4*10;A =[ 10 40 70 100 ][ 20 50 80 110 ][ 30 60 90 120 ]

#> A.( [2,6,10] ); // A.entry( [2,6,10] ), argument is matrix only ans = [ 20 60 100 ]

#> A.( [2,6,10] ) = 0; // writeA =[ 10 40 70 0 ][ 0 50 80 110 ][ 30 0 90 120 ]

#> B = [ -1, 2, 0, -3, 4 ] ;B = [ -1 2 0 -3 4 ]

#> B < 0 ; // true(1) or false(0)ans = [ 1 0 0 1 0 ]

#> B .( B < 0 ) = 10 ; // modify B if b_ij < 0B = [ 10 2 0 10 4 ]

----------------------------------------------------------------------Error Function double erf (double x) matrix erf (matrix x), for real-part only----------------------------------------------------------------------

82

Page 83: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

erf ( x )= 2√π∫0

x

e−z 2

dz

#> erf(0.5); ans = 0.52049988

#> erf( [0.5,0.6] ); ans = [ 0.5205 0.603856 ]

----------------------------------------------------------------------Complementary Error Function double erfc (double x) matrix erfc (matrix x), for real-part only----------------------------------------------------------------------

erfc ( x )=1−erf ( x )=1− 2√ π∫0

x

e− z2

dz

#> erfc(1); ans = 0.15729921

#> erfc( [1,2] ); ans = [ 0.157299 0.00467773 ]

---------------------------------------------------------------------- poly p.even ----------------------------------------------------------------------Even power only for a polynomial

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p . even=a0+a2 x2+a4 x

4+a6 x6+…

#> p = poly( 1,2,3,4,5,6,7 ) ; p = poly( 1 2 3 4 5 6 7 ) = 7x^6 +6x^5 +5x^4 +4x^3 +3x^2 +2x +1

#> p .even; ans = poly( 1 0 3 0 5 0 7 ) = 7x^6 +5x^4 +3x^2 +1

----------------------------------------------------------------------Exponential Function double exp (double x) complex exp (complex z) matrix exp (matrix A) ----------------------------------------------------------------------

83

Page 84: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

ex=1+x+ x2

2!+ x3

3 !+…+ xn

n !+…

#> exp(1); ans = 2.7182818

#> exp(1+1i); ans = 1.46869 + 2.28736!

#> exp( [1, 1+1i] ); ans = [ 2.71828 1.46869 + i 2.28736 ]

---------------------------------------------------------------------- double expint/.E1 (double x) matrix expint/.E1 (matrix A) ----------------------------------------------------------------------

E1 ( z )=∫z

∞ e−t

tdt=∫

1

∞ e− zt

tdt=−γ−ln z+z− z2

2 !2+ z3

3 !3+…+(−1 )n+1 zn

n !n+…

#> .E1(3) ans = 0.013048381

#> .E1( [3,4] ); ans = [ 0.0130484 0.00377935 ]

----------------------------------------------------------------------Matrix Exponential Function matrix expm (matrix A) ----------------------------------------------------------------------

e A=I+A+ A2

2 !+ A

3

3 !+…+ An

n !+…

#> A = [1,0.3; 0.2,1]; E = expm(A); A = [ 1 0.3 ] [ 0.2 1 ] E = [ 2.80024 0.823664 ] [ 0.549109 2.80024 ]

Especially, expm(A) can be approximately computed by

#> p = poly(0:10).fact .inv ;;#> p[A]; ans =

84

Page 85: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 2.80024 0.823664 ] [ 0.549109 2.80024 ]

---------------------------------------------------------------------- double expm1 (double x) matrix expm1(matrix A) ----------------------------------------------------------------------

ex−1=x+ x2

2 !+ x

3

3 !+…+ xn

n !+…

#> expm1(1.e-30); exp(1.e-30)-1; ans = 1e-030 ans = 0

---------------------------------------------------------------------- matrix A.ext(double m, double n, double s) ----------------------------------------------------------------------A p×q matrix becomes a ( p+m )×(q+n) matrix by extending. Elements of new entries are assigned by s

#> matrix.format("%6g");#> A = (1:16)._4 ; A =[ 1 5 9 13 ][ 2 6 10 14 ][ 3 7 11 15 ][ 4 8 12 16 ]

#> A.ext(3,4, 0.); // A.extendans =[ 1 5 9 13 0 0 0 0 ][ 2 6 10 14 0 0 0 0 ][ 3 7 11 15 0 0 0 0 ][ 4 8 12 16 0 0 0 0 ][ 0 0 0 0 0 0 0 0 ][ 0 0 0 0 0 0 0 0 ][ 0 0 0 0 0 0 0 0 ]

[ F ]

----------------------------------------------------------------------Factorial Function double .fact (double x)

85

Page 86: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

matrix .fact (matrix A) ---------------------------------------------------------------------- #> .fact(5); ans = 120

#> .fact( [5,pi] ); ans = [ 120 7.18808 ]

---------------------------------------------------------------------- double x.fact matrix A.fact poly p.fact----------------------------------------------------------------------factorial of x, x (x−1 ) ( x−2 ) ( x−3 )⋯

#> 5.fact; ans = 120

#> (-0.5).fact; // (−1 / 2 )!=√π ans = 1.7724537

#> sqrt(pi); ans = 1.7724539

For a matrix and a polynomial, element-by-element approach is applied.

---------------------------------------------------------------------- matrix factor (double x) ----------------------------------------------------------------------factorization of an integer

#> .factor(2520); // 2520 = (2)(2)(2)(3)(3)(5)(7) ans = [ 2 2 2 3 3 5 7 ]

---------------------------------------------------------------------- matrix A.false ----------------------------------------------------------------------index for zero elements

#> A = [ 2,0,3; 0,-1,0; 0,2,4 ]; A = [ 2 0 3 ] [ 0 -1 0 ] [ 0 2 4 ]

#> A.false; ans = [ 2 3 4 8 ]

86

Page 87: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.true; ans = [ 1 5 6 7 9 ]

---------------------------------------------------------------------- double fix (double x) matrix fix (matrix A) ----------------------------------------------------------------------integer near zero

#> .fix(pi); ans = 3

#> .fix( [pi, -pi] ); ans = [ 3 -3 ]

---------------------------------------------------------------------- double x.fix ----------------------------------------------------------------------integer near zero

#> pi.fix; ans = 3

#> (-pi).fix; ans = -3

---------------------------------------------------------------------- matrix A.fliplr----------------------------------------------------------------------reverse columns, flip left-right

A=[a1 a4 a7 a10

a2 a5 a8 a11

a3 a6 a9 a12] , A . fliplr=[a10 a7 a4 a1

a11 a8 a5 a2

a12 a9 a6 a3]

#> A = [ 1,2,3,4; 5,6,7,8 ]; A = [ 1 2 3 4 ] [ 5 6 7 8 ]

#> A.fliplr; ans = [ 4 3 2 1 ] [ 8 7 6 5 ]

87

Page 88: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- matrix A.flipud ----------------------------------------------------------------------reverse rows, flip upside-down

A=[a1 a4 a7 a10

a2 a5 a8 a11

a3 a6 a9 a12] , A . flipud=[a3 a6 a9 a12

a2 a5 a8 a11

a1 a4 a7 a10]

#> A = [ 1,2; 3,4; 5,6 ]; A = [ 1 2 ] [ 3 4 ] [ 5 6 ]

#> A.flipud; ans = [ 5 6 ] [ 3 4 ] [ 1 2 ]

---------------------------------------------------------------------- double floor (double x) matrix floor (matrix A) ----------------------------------------------------------------------integer near −∞

#> floor(pi); ans = 3

#> floor( [pi,-pi] ); ans = [ 3 -4 ]

---------------------------------------------------------------------- double x.floor ----------------------------------------------------------------------integer near −∞

#> pi.floor; ans = 3

#> (-pi).floor; ans = -4

---------------------------------------------------------------------- void poly.format(string fmt)

88

Page 89: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------set the format for screen output

poly.format("") retrieves a default format.

#> p = poly( pi, 1.e-5 ) ; p = poly( 3.1416e+000 1.0000e-005) = 1e-005x +3.14159

#> poly.format("%25.16e") ; p ; poly.format(""); p = poly( 3.1415926535897931e+000 1.0000000000000001e-005) = 1e-005x +3.14159

---------------------------------------------------------------------- matrix A.forsub----------------------------------------------------------------------For an n×(n+1) matrix, forward substitution is carried out to find a solution vector.

a11 x1 ¿ b1

a21 x1+a22 x2 ¿ b2

a31 x1+a32 x2+a33 x3 ¿ b3

x1=b1 / a11

x2=(b2−a21 x1 ) / a22

x3=(b3−a31 x1−a32 x2 ) / a33

#> A = [ 3,0,0, -6; 4,7,0, 13; 1,5,-4, -3 ]; A = [ 3 0 0 -6 ] [ 4 7 0 13 ] [ 1 5 -4 -3 ]

#> A.forsub; ans = [ -2 ] [ 3 ] [ 4 ]

[ G ]

----------------------------------------------------------------------

89

Page 90: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

Gamma Function double .G(double x) // dot-only matrix .G(matrix x) ----------------------------------------------------------------------

Γ ( x )=( x−1 ) !=∫0

x

t x−1e−tdt

#> .G(0.5); sqrt(pi); ans = 1.7724537 ans = 1.7724539

#> .G(6); 5.fact; // G(n+1) = n! ans = 120 ans = 120

---------------------------------------------------------------------- matrix A.gausselim ----------------------------------------------------------------------Gauss-elimination without row-swaps (without pivot)

A=[ a11 a12 a13 a14 a15 a16

a21 a22 a23 a24 a25 a26

a31 a32 a33 a34 a35 a36

a41 a42 a43 a44 a45 a46]

A .gausselim=[a11 a12 a13 a14 a15 a16

0 a22¿ a23

¿ a24¿ a25

¿ a26¿

0 0 a33¿∗¿¿a34

¿∗¿ ¿a35¿∗¿¿a36

¿∗¿ ¿0 0 0 ¿a45

¿∗¿¿a46

¿∗¿¿]

#> A = [ 1,-2,-5,6; 3,-7,0,2; -5,3,-4,-8 ]; A = [ 1 -2 -5 6 ] [ 3 -7 0 2 ] [ -5 3 -4 -8 ]

#> A.gausselim;; ans = [ 1 -2 -5 6 ] [ 0 -1 15 -16 ] [ 0 0 -134 134 ]

user-code can be written as follows.matrix gausselim(A) { // copy A n = A.m;

90

Page 91: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

for.k(1,n-1) { if( |A(k,k)| < _eps ) break; prow = A.row(k)/A(k,k); for.i(k+1,n) { A.row(i) -= A(i,k)*prow; A(i,k) = 0; A;; // display } cut;; } return A;}#> gausselim(A);; gausselim.A = [ 1 -2 -5 6 ] [ 0 -1 15 -16 ] [ -5 3 -4 -8 ] gausselim.A = [ 1 -2 -5 6 ] [ 0 -1 15 -16 ] [ 0 -7 -29 22 ]------------------------------------------------------------ gausselim.A = [ 1 -2 -5 6 ] [ 0 -1 15 -16 ] [ 0 0 -134 134 ]------------------------------------------------------------

---------------------------------------------------------------------- matrix A.gaussjord ----------------------------------------------------------------------Gauss-Jordan elimination with pivot (switching rows)

A=[ a11 a12 a13 a14 a15 a16

a21 a22 a23 a24 a25 a26

a31 a32 a33 a34 a35 a36

a41 a42 a43 a44 a45 a46]

A .gaussjord=[1 0 0 0 ap5 ap6

0 1 0 0 ap5¿ ap6

¿

0 0 1 0 a p5¿∗¿ ¿ap6

¿∗¿¿0 ¿0¿1¿ap5

¿∗¿¿ap6

¿∗¿¿ ]

where a pj represents a pivoted coefficient.

#> A = [ 1,-2,-5,6; 3,-7,0,2; -5,3,-4,-8 ]; A = [ 1 -2 -5 6 ] [ 3 -7 0 2 ]

91

Page 92: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ -5 3 -4 -8 ]

#> A.gaussjord; ans = [ 1 0 0 3 ] [ 0 1 0 1 ] [ 0 0 1 -1 ]

user-code can be written as follows.

matrix gaussjord(A) { // copy A n = A.m; for.k(1,n) { // up to the last line // pivoting procedure below //imax = k; //pmax = |A(k,k)|; //for.i(k+1,n) { // if( pmax < |A(i,k)| ) { pmax = |A(i,k)|; imax = i; } //} imax = A..(k:n)(k).maxentryk +k-1; if( imax != k ) { [ k,imax ];; A = A.swap(imax,k);; } // elimination procedure if( |A(k,k)| < _eps ) continue; // _eps = 2.22e-16 A.row(k) /= A(k,k); for.i(1,n) { if( i == k ) continue; // skip if k=i A.row(i) -= A(i,k)*A.row(k); A(i,k) = 0.; A;; // display } cut;; } return A;}#> gaussjord(A);; gaussjord.ans = [ 1 3 ] gaussjord.A = [ -5 3 -4 -8 ] [ 3 -7 0 2 ] [ 1 -2 -5 6 ] gaussjord.A = [ 1 -0.6 0.8 1.6 ] [ 0 -5.2 -2.4 -2.8 ] [ 1 -2 -5 6 ] gaussjord.A = [ 1 -0.6 0.8 1.6 ] [ 0 -5.2 -2.4 -2.8 ] [ 0 -1.4 -5.8 4.4 ]------------------------------------------------------------ gaussjord.A =

92

Page 93: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 1 0 1.07692 1.92308 ] [ -0 1 0.461538 0.538462 ] [ 0 -1.4 -5.8 4.4 ] gaussjord.A = [ 1 0 1.07692 1.92308 ] [ -0 1 0.461538 0.538462 ] [ 0 0 -5.15385 5.15385 ]------------------------------------------------------------ gaussjord.A = [ 1 0 0 3 ] [ -0 1 0.461538 0.538462 ] [ -0 -0 1 -1 ] gaussjord.A = [ 1 0 0 3 ] [ 0 1 0 1 ] [ -0 -0 1 -1 ]------------------------------------------------------------

---------------------------------------------------------------------- matrix A.gausspivot ----------------------------------------------------------------------Gauss-elimination with pivot (row-swaps)

A=[ a11 a12 a13 a14 a15 a16

a21 a22 a23 a24 a25 a26

a31 a32 a33 a34 a35 a36

a41 a42 a43 a44 a45 a46]

A .gausspivot=[ap1 a p2 ap3 ap4 ap5 ap6

0 a p2¿ ap3

¿ ap4¿ ap5

¿ ap6¿

0 0 ap3¿∗¿¿ ap4

¿∗¿ ¿ap5¿∗¿¿ ap6

¿∗¿ ¿0 0 0 ¿ap5

¿∗¿¿a p6

¿∗¿¿]

where a pj represents a pivoted coefficient.

#> A = [ 1,-2,-5,6; 3,-7,0,2; -5,3,-4,-8 ]; A = [ 1 -2 -5 6 ] [ 3 -7 0 2 ] [ -5 3 -4 -8 ]

#> A.gausspivot; ans = [ -5 3 -4 -8 ] [ 0 -5.2 -2.4 -2.8 ] [ 0 0 -5.15385 5.15385 ]

#> A.rowswap(1,3).add(2,1, 3/5).add(3,1, 1/5).add(3,2, -1.4/5.2); ans =

93

Page 94: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ -5 3 -4 -8 ] [ 0 -5.2 -2.4 -2.8 ] [ 0 0 -5.15385 5.15385 ]

// Gauss elimination with pivot, user code for A.gausspivotmatrix gausspivot(A) { // copy A n = A.m; for.k(1,n-1) { // pivoting procedure below //imax = k; //pmax = |A(k,k)|; //for(i = k+1; i <= n; i++) { // if( pmax < |A(i,k)| ) { pmax = |A(i,k)|; imax = i; } //} imax = A..(k:n)(k).maxentryk +k-1; if( imax != k ) { [ k,imax ];; A = A.swap(imax,k);; } // elimination procedure if( |A(k,k)| < _eps ) continue; // _eps = 2.22e-16 prow = A.row(k)/A(k,k); for.i(k+1,n) { if( i == k ) continue; // skip if k=i A.row(i) -= A(i,k)*prow; A(i,k) = 0.; A;; // display } cut;; } return A;}#> gausspivot(A);; gausspivot.ans = [ 1 3 ] gausspivot.A = [ -5 3 -4 -8 ] [ 3 -7 0 2 ] [ 1 -2 -5 6 ] gausspivot.A = [ -5 3 -4 -8 ] [ 0 -5.2 -2.4 -2.8 ] [ 1 -2 -5 6 ] gausspivot.A = [ -5 3 -4 -8 ] [ 0 -5.2 -2.4 -2.8 ] [ 0 -1.4 -5.8 4.4 ]------------------------------------------------------------ gausspivot.A = [ -5 3 -4 -8 ] [ 0 -5.2 -2.4 -2.8 ] [ 0 0 -5.15385 5.15385 ]------------------------------------------------------------

----------------------------------------------------------------------

94

Page 95: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

double .gcd (double a, double b) // dot-only matrix .gcd (double a, matrix b) matrix .gcd (matrix a, double b) matrix .gcd (matrix a, matrix b)----------------------------------------------------------------------greatest common divisor

#> .gcd(24,36); ans = 12

[ H ]

----------------------------------------------------------------------Heaviside Function double .H(double x) // dot-only matrix .H(matrix x) ----------------------------------------------------------------------

H ( x )={0 , x<01 , x>0

#> .H(-1); ans = 0

#> .H(3); ans = 1

---------------------------------------------------------------------- double .H_n(double x) // dot-only matrix .H_n(matrix x), for real-part only----------------------------------------------------------------------evaluation of the Hermite polynomial of degree n

#> .H_5(0.3); ans = 31.75776

#> .H_5( [0.3,0.4] ); ans = [ 31.7578 38.0877 ]

#>.hold; for.n(1,5) plot.x(-1,1) ( .H_n(x) ); plot;

95

Page 96: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- poly poly.H(double n) ----------------------------------------------------------------------Hermite polynomial of degree n

H 0 ( x )=1 ,H 1 ( x )=2xH n ( x )=2 x H n−1 ( x )−2 (n−1 )H n−2(x )

#> for.n(0,5) poly.H(n); ans = poly( 1 )

= 1 ans = poly( 0 2 ) = 2x ans = poly( -2 0 4 ) = 4x^2 -2 ans = poly( -0 -12 0 8 ) = 8x^3 -12x ans = poly( 12 -0 -48 0 16 ) = 16x^4 -48x^2 +12 ans = poly( 0 120 -0 -160 0 32 ) = 32x^5 -160x^3 +120x

----------------------------------------------------------------------Hankel function by Bessel Function complex .H1_nu(double x) dot-only complex .H2_nu(double x) dot-only matrix .H1_nu(matrix x), for real-part only matrix .H2_nu(matrix x), for real-part only----------------------------------------------------------------------

H ν(1) ( x )=J ν ( x )+iY ν ( x )

H ν(2 )( x )=J ν ( x )−i Y ν (x )

#> .H1_0.5(1.2); .H2_0.5(1.2); ans = 0.678865 - 0.263929! ans = 0.678865 + 0.263929!

96

Page 97: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> .J_0.5(1.2); .Y_0.5(1.2); ans = 0.67886517 ans = -0.26392895

#> .H1_0.5( [1.2, 2.4] ); .H2_0.5( [1.2, 2.4] );

ans = [ 0.678865 - i 0.263929 0.347885 + i 0.379782 ] ans = [ 0.678865 + i 0.263929 0.347885 - i 0.379782 ]

---------------------------------------------------------------------- matrix matrix.hank (matrix A, matrix B) ----------------------------------------------------------------------#> matrix.hank ([3,1,2,0],[0,-1,-2,-3]); // hankelans = [ 3 1 2 0 ] [ 1 2 0 -1 ] [ 2 0 -1 -2 ] [ 0 -1 -2 -3 ]

---------------------------------------------------------------------- matrix A.hess----------------------------------------------------------------------eigenvalue-preserving Hessenberg matrix

#> A = [ 4,3,-2,1; 3,1,7,9; -2,7,5,4; 1,9,4,2 ]; A = [ 4 3 -2 1 ] [ 3 1 7 9 ] [ -2 7 5 4 ] [ 1 9 4 2 ]

#> A .hess .trun12; // built-in function ans = [ 4 -3.74166 0 0 ] [ -3.74166 -1.07143 6.83441 0 ] [ 0 6.83441 7.29972 9.24686 ] [ 0 0 9.24686 1.77171 ]

#> A.eig; A.hess.eig; ans = [ 5.61943 ] [ -8.47695 ] [ -1.2945 ] [ 16.152 ] ans = [ 5.61943 ] [ -8.47695 ] [ -1.2945 ] [ 16.152 ]

97

Page 98: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- matrix A.high(double m) ----------------------------------------------------------------------reshape in m -rows

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.high(5); ans = [ 1 6 11 ] [ 2 7 12 ] [ 3 8 0 ] [ 4 9 0 ] [ 5 10 0 ]

---------------------------------------------------------------------- matrix matrix.hilb (double n) ----------------------------------------------------------------------

a ij=1i+ j

#> matrix.hilb(4);

ans = [ 1 0.5 0.333333 0.25 ] [ 0.5 0.333333 0.25 0.2 ] [ 0.333333 0.25 0.2 0.166667 ] [ 0.25 0.2 0.166667 0.142857 ]

---------------------------------------------------------------------- matrix .horzcat( ...) ----------------------------------------------------------------------horizontal concatenation.

#> .horzcat( 1,2, [ 3;4;5 ], 6, [-1;-2] ) ans = [ 1 2 3 6 -1 ] [ 0 0 4 6 -2 ] [ 0 0 5 6 0 ]

Operation is carried out in sequence. Therefore, the first two entries 1 and 2 have all-zeros below. But the fourth entry (6) is extended as a matrix.

98

Page 99: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ I ]

----------------------------------------------------------------------Identity matrix matrix .I(double m, double n=m) dot-only matrix .eye(double m, double n=m)----------------------------------------------------------------------

a ij=δij={1 i= j0 i ≠ j

#> .I(3,4); ans = [ 1 0 0 0 ] [ 0 1 0 0 ] [ 0 0 1 0 ]

#> .I(4); ans = [ 1 0 0 0 ] [ 0 1 0 0 ] [ 0 0 1 0 ] [ 0 0 0 1 ]

----------------------------------------------------------------------Bessel Function double .I_(double nu)(double x) dot-only matrix .I_(double nu)(matrix x) matrix .I_(matrix nu)(double x) matrix .I_(matrix nu)(matrix x) ----------------------------------------------------------------------

I ν ( x )=∑i=0

∞ 1s ! ( s+ν )! ( x2 )

2 s+ ν

#> nu = 1;;#> .I_nu+1/2(0.3); ans = 0.044096517

#> .I_nu+1/2( [0.3,0.4] ); ans = [ 0.0440965 0.0683662 ]

#> .I_[1.5;2.5]( [0.3,0.4] ); ans = [ 0.0440965 0.0683662 ] [ 0.00263901 0.00544447 ]

99

Page 100: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> .hold; for.nu(0,5) plot.x(0,2) ( .I_nu(x)); plot;

---------------------------------------------------------------------- double A.i(double k) ----------------------------------------------------------------------i of index (i,j) for linear index k=i+m( j−1)

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> i = A.i(8); i = 2

---------------------------------------------------------------------- (double i, double j) = A.ij(double k) // tuple----------------------------------------------------------------------index (i,j) for linear index k=i+m( j−1)

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> (i,j) = A.ij(8); i = 2 j = 3

#> A.k(2,3); ans = 8

---------------------------------------------------------------------- matrix W.imag // both read/write----------------------------------------------------------------------imaginary part

100

Page 101: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A = [ 1-2i, -3+4i; 2+3i, 5+2i ]; A = [ 1 - i 2 -3 + i 4 ] [ 2 + i 3 5 + i 2 ]

#> A.imag; ans = [ -2 4 ] [ 3 2 ]

#> A.imag += 100; // matrix is modified, writable A = [ 1 + i 98 -3 + i 104 ] [ 2 + i 103 5 + i 102 ]

---------------------------------------------------------------------- matrix A.ins(double i,double j,matrix B)----------------------------------------------------------------------insert B at (i,j) position

#> A = (1:16)._4;A =[ 1 5 9 13 ][ 2 6 10 14 ][ 3 7 11 15 ][ 4 8 12 16 ]

#> A.ins(1,1, [101:105; 201:205]); // [101:105; 201:205] \_ A ans =[ 101 102 103 104 105 0 0 0 0 ][ 201 202 203 204 205 0 0 0 0 ][ 0 0 0 0 0 1 5 9 13 ][ 0 0 0 0 0 2 6 10 14 ][ 0 0 0 0 0 3 7 11 15 ][ 0 0 0 0 0 4 8 12 16 ]

#> A.ins(2,2, [101:105; 201:205]');ans =[ 1 0 0 5 9 13 ][ 0 101 201 0 0 0 ][ 0 102 202 0 0 0 ][ 0 103 203 0 0 0 ][ 0 104 204 0 0 0 ][ 0 105 205 0 0 0 ][ 2 0 0 6 10 14 ][ 3 0 0 7 11 15 ][ 4 0 0 8 12 16 ]

101

Page 102: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.ins(100,100, [101:105; 201:205]'); // A \_ [101:105; 201:205]'ans =[ 1 5 9 13 0 0 ][ 2 6 10 14 0 0 ][ 3 7 11 15 0 0 ][ 4 8 12 16 0 0 ][ 0 0 0 0 101 201 ][ 0 0 0 0 102 202 ][ 0 0 0 0 103 203 ][ 0 0 0 0 104 204 ][ 0 0 0 0 105 205 ]

---------------------------------------------------------------------- double .integ(double a,double b,double f(double x)) // dot-only----------------------------------------------------------------------general integration including indefinite integral

∫−∞

b

f ( x )dx ,∫a

f ( x )dx ,∫−∞

f (x )dx ,∫a

b

f ( x )dx

inf = ∞//-------------------// indefinite integral//-------------------double integ(a,b, f(x)) { aa = a; bb = b; flip = 1; if(a > b) { aa = b; bb = a; flip = -1; } (sum, h,r) = (0, 0.05, 1.2); if( aa < -0.5*inf && 0.5*inf < bb ) { // -inf<x<inf a = 0; for[300] { sum += int.x(a,a+h) ( f(x) ) + int.x(-a-h,-a) ( f(x) ); a += h; h *= r; } } else if( aa < -0.5*inf ) { // -inf<x<bb a = bb; for[300] { sum += int.x(a-h,a) ( f(x) ); a -= h; h *= r; } } else if( 0.5*inf < bb ) { // aa<x<inf a = aa; for[300] { sum += int.x(a,a+h) ( f(x) ); a += h; h *= r; } } else { // aa<x<bb a = b = 0.5*(aa+bb); h = 0.25*(bb-aa); for[30] { sumo = sum;

102

Page 103: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

sum += int.x(a,a+h) (f(x)) + int.x(b-h,b) (f(x)); a += h; b -= h; h *= 0.5; if( sum.-.sumo < 1.e-8) break; } }

return sum*flip;}

∫0

e−x2

sin (x2)dx=√π4

(√2−1 )1 / 2

#> double f(x) = exp(-x^2)*sin(x^2); // exercise 9(f)#> integ(0,inf,f); // user function listed above#> .integ(0,inf,f); // built-in dot function ans = 0.28518528 ans = 0.28518528

#> sqrt(pi)/4*sqrt(sqrt(2)-1);ans = 0.28518528

∫0

1 1√1−x2

dx=sin−1(1)

#> double f(x) = 1/sqrt(1-x^2);#> integ(0,1,f); // user function listed above#> .integ(0,1,f); // built-in dot function ans = 1.5707658 ans = 1.5707658

#> asin(1); ans = 1.5707963

---------------------------------------------------------------------- poly .interp(matrix X, matrix Y)----------------------------------------------------------------------interpolating polynomial

#> x = [ 1,2,3,4 ]; y = [ 10,20,48,100 ]; x = [ 1 2 3 4 ] y = [ 10 20 48 100 ]

#> .interp(x,y); ans(x); // pass all points ans = poly( 12 -6 3 1 ) = x^3 +3x^2 -6x +12 ans = [ 10 20 48 100 ]

---------------------------------------------------------------------- matrix A.inv ----------------------------------------------------------------------

103

Page 104: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

inverse matrix, A.inv * A = .I(A)

#> A = [ 1+2i, 3-4i; -2+1i, 5+2i ]; A = [ 1 + i 2 3 - i 4 ] [ -2 + i 1 5 + i 2 ]

#> A.inv; ans = [ 1.7 + i 0.1 -0.5 + i 1.5 ] [ 0.5 - i 0.5 0.5 + i 0.5 ]

#> A.inv * A ; ans = [ 1 0 ] [ 0 1 ]

#> A.inv*A - .I(A);

ans = [ 0 0 ] [ 0 0 ]

---------------------------------------------------------------------- poly p.inv ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .inv=1 / a0+(1 / a1 )x+(1 / a2 ) x2+…+¿

#> .[ 1,2,3,4 ] .inv ; // x^3 + 2x^2 + 3x + 4ans = poly( 0.25 0.333333 0.5 1 )

= x^3 +0.5x^2 +0.333333x +0.25

---------------------------------------------------------------------- poly p.invtay ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .invtay=a0+a1 x+2! a2 x2+3 !a3 x

3+…+n!an xn

#> .[ 1,2,3,4 ] .invtay; ans = poly( 4 3 4 6 ) = 6x^3 +4x^2 +3x +4

---------------------------------------------------------------------- double A.ipos(double x)

104

Page 105: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------returns an index, ak≤ x≤ak+1

#> A = [ 1,6,16,25; 3,9,18,30; 4,15,21,40 ]; A = [ 1 6 16 25 ] [ 3 9 18 30 ] [ 4 15 21 40 ]

#> A.ipos(8.3); // a(4)=6 <= x <= a(5)=9 ans = 4

#> A.ipos(35); // a(11)=30 <= x <= a(12)=40 ans = 11

#> A.ipos(-5); A.ipos(100); // out of range ans = 0 ans = 0

---------------------------------------------------------------------- poly p.iratio ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

shows a rational approximation of each coefficient

#> poly(0.1, 0.2, 1.5).iratio ;ans = poly( 1/10 1/5 3/2 )

---------------------------------------------------------------------- double .isprime (double x) ----------------------------------------------------------------------return 1 if x is a prime number, otherwise return 0

#> .isprime(37); ans = 1#> .isprime(36); ans = 0

---------------------------------------------------------------------- double A.isreal----------------------------------------------------------------------return 1 if a matrix is real, otherwise return 0

#> [ 1+2i ].isreal; [ 3 ].isreal; ans = 0 ans = 1

105

Page 106: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- double A.issquare ----------------------------------------------------------------------returns 1 if a matrix is square, otherwise return 0

#> [ 1,2; 3,4 ].issquare; [ 1,2,3,4 ].issquare; ans = 1 ans = 0

[ J ]

----------------------------------------------------------------------Bessel Function double .J_(double nu)(double x) dot-only matrix .J_(double nu)(matrix x) matrix .J_(matrix nu)(double x) matrix .J_(matrix nu)(matrix x) ----------------------------------------------------------------------

Jν ( x )=∑i=0

∞ (−1 ) s

s! (s+ν ) ! ( x2 )2 s+ν

#> nu = 1;;#> .J_nu+1/2(0.3); ans = 0.043309878

#> .J_nu+1/2( [0.3,0.4] ); ans = [ 0.0433099 0.0662131 ]

#> .J_[1.5;2.5] ( [0.3,0.4] ); ans = [ 0.0433099 0.0662131 ] [ 0.0026053 0.00532144 ]

#> .hold; for.nu(0,5) plot.x(0,15) (.J_nu(x)); plot;

106

Page 107: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------Spherical Bessel Function double .j_(double nu)(double x) dot-only matrix .j_(double nu)(matrix x) matrix .j_(matrix nu)(double x) matrix .j_(matrix nu)(matrix x) ----------------------------------------------------------------------

jn ( x )=√ π2x

Jn+1 / 2(x)

j0 ( x )= sin xx

#> .j_0(0.5); sin(0.5)/0.5; ans = 0.958851 ans = 0.95885108

#> .j_0( [0.5,1] ); ans = [ 0.958851 0.841471 ]

#> .j_[0;1] ( [0.5,1] ); ans = [ 0.958851 0.841471 ] [ 0.162537 0.301169 ]

---------------------------------------------------------------------- double A.j(double k) ----------------------------------------------------------------------j of index (i,j) for linear index k=i+m( j−1)

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> j = A.j(8); j = 3

---------------------------------------------------------------------- matrix matrix.jord (double a, double b) matrix matrix.jordan (double a, double b) ----------------------------------------------------------------------#> matrix.jordan(4,1); ans = [ 1 1 0 0 ]

107

Page 108: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 0 1 1 0 ] [ 0 0 1 1 ] [ 0 0 0 1 ]

---------------------------------------------------------------------- matrix A.jord(double i) ----------------------------------------------------------------------eliminates rows above and below a ii through elementary row operations.

#> A = [ 1,-2,-5,6; 3,-7,0,2; -5,3,-4,-8 ];A = [ 1 -2 -5 6 ] [ 3 -7 0 2 ] [ -5 3 -4 -8 ]#> A.jord(1); ans = [ 1 -2 -5 6 ] [ 0 -1 15 -16 ] [ 0 -7 -29 22 ]#> A.jord(1).jord(2);

ans = [ 1 0 -35 38 ] [ 0 1 -15 16 ] [ 0 0 -134 134 ]#> A.jord(1).jord(2).jord(3);

ans = [ 1 0 0 3 ] [ 0 1 0 1 ] [ 0 0 1 -1 ]

[ K ]

----------------------------------------------------------------------Bessel Function double .K_(double nu)(double x) dot-only matrix .K_(double nu)(matrix x) matrix .K_(matrix nu)(double x) matrix .K_(matrix nu)(matrix x) ----------------------------------------------------------------------

K ν ( x )=π2I−ν ( x )−I ν ( x )

sin νπ

#> nu = 1;;

108

Page 109: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> .K_nu+1/2(0.3); ans = 7.3456985

#> .K_nu+1/2( [0.3,0.4] ); ans = [ 7.3457 4.64922 ]

#> .K_[1.5;2.5]( [0.3,0.4] ); ans = [ 7.3457 4.64922 ] [ 75.1521 36.1975 ]

#> .hold; for.nu(0,5) plot.x(4,15) (.K_nu+0.5(x)); plot;

---------------------------------------------------------------------- double A.k(double i,double j)----------------------------------------------------------------------linear index k=i+m( j−1) for row-column index (i,j)

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.k(2,3); ans = 8

#> (i,j) = A.ij(8); i = 2 j = 3

---------------------------------------------------------------------- matrix .kron(matrix A, matrix B) ----------------------------------------------------------------------A ^^ B = .kron(A,B)A Kronecker product of m×n

matrix A and p×q matrix B results in m×n

109

Page 110: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

block-matrix dimension of mp×nq, and its (i , j) block is a ijB .

%> Kronecker product, A^^B = .kron(A,B)#> matrix.format("%6g") ;#> A = [ 1, 10, -100; -10, 1, 1000 ];; B = [ 1,2,3; 4,5,6; 7,8,9 ];;#> A ^^ B ;ans = [ 1 2 3 10 20 30 -100 -200 -300 ] [ 4 5 6 40 50 60 -400 -500 -600 ] [ 7 8 9 70 80 90 -700 -800 -900 ] [ -10 -20 -30 1 2 3 1000 2000 3000 ] [ -40 -50 -60 4 5 6 4000 5000 6000 ] [ -70 -80 -90 7 8 9 7000 8000 9000 ]

Cemmath extends the concept of the Kronecker product to handle various operatations more than multiplication via the upgraded function. For example, the above Kronecker product is the same as

#> matrix kronmul(double x) = x * [ 1, 10, -100; -10, 1, 1000 ] ;#> B = [ 1,2,3; 4,5,6; 7,8,9 ];; #> kronmul++(B); // upgraded matrix(double) ans = [ 1 2 3 10 20 30 -100 -200 -300 ] [ 4 5 6 40 50 60 -400 -500 -600 ] [ 7 8 9 70 80 90 -700 -800 -900 ] [ -10 -20 -30 1 2 3 1000 2000 3000 ] [ -40 -50 -60 4 5 6 4000 5000 6000 ] [ -70 -80 -90 7 8 9 7000 8000 9000 ]

another example

#> matrix.format("%9g");#> matrix kron3(double x) = [ x, 1, -sqrt(x); 0, x^2, log(x) ] ; #> kron3++( [2,3;4,5] ); // upgraded matrix(double) ans = [ 2 3 1 1 -1.41421 -1.73205 ] [ 4 5 1 1 -2 -2.23607 ] [ 0 0 4 9 0.693147 1.09861 ] [ 0 0 16 25 1.38629 1.60944 ]

[ L ]

110

Page 111: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- double .L_n(double x) dot-only matrix .L_n(matrix x), for real-part only----------------------------------------------------------------------Laguerre polynomial

#> .L_5(0.3); ans = -11.19993

#> .L_5( [0.3,0.4] ); ans = [ -11.1999 -36.1702 ]

#> .hold; for.n(1,5) plot.x(0,1) ( .L_n(x) ); plot;

---------------------------------------------------------------------- poly poly.L(n) ----------------------------------------------------------------------Laguerre polynomial of degree n

L0 ( x )=1 , L1 (x )=1−xLn ( x )=(2n−x−1 ) Ln−1 ( x )−(n−1 )2Ln−2(x )

#> for.n(0,5) poly.L(n); ans = poly( 1 )

= 1 ans = poly( 1 -1 ) = -x +1 ans = poly( 2 -4 1 ) = x^2 -4x +2 ans = poly( 6 -18 9 -1 ) = -x^3 +9x^2 -18x +6 ans = poly( 24 -96 72 -16 1 ) = x^4 -16x^3 +72x^2 -96x +24 ans = poly( 120 -600 600 -200 25 -1 ) = -x^5 +25x^4 -200x^3 +600x^2 -600x +120

---------------------------------------------------------------------- double .lcm (double a, double b) dot-only

111

Page 112: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

matrix .lcm (double a, matrix b) matrix .lcm (matrix a, double b) matrix .lcm (matrix a, matrix b)----------------------------------------------------------------------least common multiplier

#> .lcm(24,36); ans = 72

---------------------------------------------------------------------- void poly.left(string fmt) ----------------------------------------------------------------------set the left delimiter for screen output

#> p = poly( 1,2,3 ) ; p = poly( 1 2 3 ) = 3x^2 +2x +1

#> poly.left("[]()left<>--->") ; p ; p = []()left<>---> 1 2 3 ) = 3x^2 +2x +1

---------------------------------------------------------------------- double p.len ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .len=n+1#> p = (1:5).dpoly; p = poly( 5 4 3 2 1 ) = x^4 +2x^3 +3x^2 +4x +5#> p.len;

ans = 5

---------------------------------------------------------------------- matrix A.len matrix A.length matrix A.longer----------------------------------------------------------------------return max (m,n) for an m×n matrix A

#> A = (1:6)._3; A = [ 1 3 5 ] [ 2 4 6 ]#> A.len; ans = 3

112

Page 113: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- double .lnG/logG(double x) // dot-only matrix .lnG/logG(matrix x) ----------------------------------------------------------------------

ln (Γ ( x ))=ln∫0

x

t x−1 e−tdt

#> .lnG(0.5); log(sqrt(pi)); ans = 0.57236486 ans = 0.57236494

#> .lnG(6); log(5.fact); // G(n+1) = n! ans = 4.7874917 ans = 4.7874917

----------------------------------------------------------------------Logarithmic Function with base _e double log (double x) matrix log (matrix A) ----------------------------------------------------------------------#> log(2); log(_e); log(10); ans = 0.69314718 ans = 1 ans = 2.3025851#> log( [2,_e,10] ); ans = [ 0.693147 1 2.30259 ]

---------------------------------------------------------------------- double log1p (double x) matrix log1p (matrix A) ----------------------------------------------------------------------

ln (1+x )=x− x2

2+ x

3

3− x5

5+…

#> log1p(1.e-40); log(1+1.e-40); ans = 1e-040 ans = 0

----------------------------------------------------------------------Logarithmic Function with base 2 double log2 (double x) matrix log2 (matrix A) ----------------------------------------------------------------------#> log2(2); log2(_e); log2(10); ans = 1 ans = 1.442695

113

Page 114: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

ans = 3.3219281

#> log2( [2,_e,10] ); ans = [ 1 1.4427 3.32193 ]

----------------------------------------------------------------------Logarithmic Function with base 10 double log10 (double x) matrix log10 (matrix A) ----------------------------------------------------------------------#> log10(2); log10(_e); log10(10); ans = 0.30103 ans = 0.43429448 ans = 1

#>log10( [2,_e,10] ); ans = [ 0.30103 0.434294 1 ]

---------------------------------------------------------------------- matrix logm (matrix A) ----------------------------------------------------------------------inverse of expm(A)

#> A = [1,0.3; 0.2,1]; E = expm(A); L = logm(A); A = [ 1 0.3 ] [ 0.2 1 ] E = [ 2.80024 0.823664 ] [ 0.549109 2.80024 ] L = [ -0.0309377 0.306226 ] [ 0.20415 -0.0309377 ]

#> logm(E); ans = [ 1 0.3 ] [ 0.2 1 ]

#> expm(L); ans = [ 1 0.3 ] [ 0.2 1 ]

---------------------------------------------------------------------- matrix (double a, double b) .logspan (double n, double g=1)

114

Page 115: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------(a,b) .logspan(n,g=1) // 10.^( (log10(a),log10(b)).span(n,g=1) )

%> (a,b) .logspan(n,g=1) has a matrix of dimension 1 x n ---------------#> x = (1,10).logspan(11); log10(x);x =[ 1 1.25893 1.58489 1.99526 2.51189 3.16228 3.98107 5.01187 6.30957 7.94328

10 ]ans =[ 0 0.1 0.2 0.3 0.4

0.5 0.6 0.7 0.8 0.9 1 ]

---------------------------------------------------------------------- (matrix L,matrix U) = A.lu // tuple----------------------------------------------------------------------A = LU decomposition

For a ij with i≥ j (i.e. lower-triangular and diagonal elements),

a ij=∑k=1

j−1

likukj+liju jj

⇒lij=aij−∑

k=1

j−1

lik ukj

For a ij with i< j (i.e. upper-triangular elements),

a ij=∑k=1

i−1

likukj+liiu jj

⇒uij=( aij−∑

k=1

i−1

likukj )/ lii

#> A = [ 2,-1,1; -1,3,-2; 1,-2,5 ];A = [ 2 -1 1 ] [ -1 3 -2 ] [ 1 -2 5 ]

#> (L,U) = A.lu; // tuple assignment by LU decompositionL = [ 2 0 0 ] [ -1 2.5 0 ] [ 1 -1.5 3.6 ]U = [ 1 -0.5 0.5 ] [ 0 1 -0.6 ] [ 0 0 1 ]

User-own code can be also written as follows.

115

Page 116: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

void user_lu(matrix& A) { n = A.m; L = U = .zeros(n);

for.s(1,n) { for.i(s,n) L(i,s) = A(i,s) - L..(i)(1:s-1) ** U..(1:s-1)(s); U(s,s) = 1; // horizontal direction for.j(s+1,n) U(s,j) = (A(s,j) - L..(s)(1:s-1) ** U..(1:s-1)(j))/L(s,s);

[ L, U ] ;; // display L..(j:n)(j), U..(i)(i:n) }}

#> user_lu(A); ans = [ 2 0 0 1 -0.5 0.5 ] [ -1 0 0 0 0 0 ] [ 1 0 0 0 0 0 ] ans = [ 2 0 0 1 -0.5 0.5 ] [ -1 2.5 0 0 1 -0.6 ] [ 1 -1.5 0 0 0 0 ] ans = [ 2 0 0 1 -0.5 0.5 ] [ -1 2.5 0 0 1 -0.6 ] [ 1 -1.5 3.6 0 0 1 ]

[ M ]

---------------------------------------------------------------------- double A.m----------------------------------------------------------------------return m for an m×n matrix A

#> A = (1:6)._3; A.m; A = [ 1 3 5 ] [ 2 4 6 ] ans = 2

---------------------------------------------------------------------- matrix (double a, double h) .march (double n, double g=1)----------------------------------------------------------------------(a,h) .march(n,g=1) // [ a, a+h(1),... , a+h(1+g+...+g^(n-2)) ]

116

Page 117: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

%> (a,h) .march(n,g=1) has a matrix of dimension 1 x n ----------------#> X = (3,1) .march(6) ; // g = 1 by defaultX = [ 3 4 5 6 7 8 ]

#> X = (3,1) .march(6,2) ; // g = 2 for increasingX = [ 3 4 6 10 18 34 ]

#> X = (3,1) .march(6,0.5) ; // g = 0.5 for decreasingX = [ 3 4 4.5 4.75 4.875 4.9375 ]

---------------------------------------------------------------------- double .max(double x1, double x2, ... ) dot-only----------------------------------------------------------------------maximum of arguments

#> .max(1,2); ans = 2

#> .max(1,2,3); ans = 3

#> .max(1,2,3,4); ans = 4

---------------------------------------------------------------------- matrix A.max // column-first operation

double A.max1 // equivalent to A.max.max(1)----------------------------------------------------------------------maximum elements

#> A = [ 0,-1,2; 1,2,-4; 5,-3,-4 ] ; A =[ 0 -1 2 ][ 1 2 -4 ][ 5 -3 -4 ]

#> A.max; ans = [ 5 2 2 ]

#> A.max.max; ans = [ 5 ]

#> A().max; ans = [ 5 ]

#> A.max1; ans = 5

117

Page 118: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- double p.max----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

returns max \{ai \}

#> p = .[ -5,2,4 ] ; p = poly( 4 2 -5 ) = -5x^2 +2x +4

#> p .max ; ans = 4

---------------------------------------------------------------------- double A.max1k/maxk----------------------------------------------------------------------#> A = [ 3,-1,2; 2,4,-3; -5,-3,-2 ] ; A = [ 3 -1 2 ] [ 2 4 -3 ] [ -5 -3 -2 ]

#> A.max1k; ans = 5

----------------------------------------------------------------------

void poly.maxcol(double n=10) ----------------------------------------------------------------------set the maximum column length for screen output

"void" means no data is returned by calling this function.The constant coefficient a0 is exempted from the counting.

#> (1:20).dpoly; // 10 terms without a_0 ans = poly( 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 ) = x^19 +2x^18 +3x^17 +4x^16 +5x^15 +6x^14 +7x^13 +8x^12 +9x^11 +10x^10 +11x^9 +12x^8 +13x^7 +14x^6 +15x^5 +16x^4 +17x^3 +18x^2 +19x +20

#> poly.maxcol(5); (1:20).dpoly; // note the difference ans = 5 ans = poly( 20 19 18 17 16 15 // 5 terms without a_0 14 13 12 11 10 9 8 7 6 5

118

Page 119: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

4 3 2 1 ) = x^19 +2x^18 +3x^17 +4x^16 +5x^15 +6x^14 +7x^13 +8x^12 +9x^11 +10x^10 +11x^9 +12x^8 +13x^7 +14x^6 +15x^5 +16x^4 +17x^3 +18x^2 +19x +20

---------------------------------------------------------------------- matrix A.maxentry ----------------------------------------------------------------------absolute maximum element

#> A = [ 0,-1,2; 1,2,-4; 5,-3,-4 ] ; A =[ 0 -1 2 ][ 1 2 -4 ][ 5 -3 -4 ]

#> A.maxentry; ans = 5

---------------------------------------------------------------------- double p.maxentry----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

returns max \{|ai |\}

#> p = .[ -5,2,4 ] ; p = poly( 4 2 -5 ) = -5x^2 +2x +4#> p .maxentry ; ans = -5

---------------------------------------------------------------------- double A.maxentryk----------------------------------------------------------------------linear index k for A.maxentry

#> A = [ 3,-1,2; 2,4,-3; -5,-3,-2 ] ; A =[ 3 -1 2 ][ 2 4 -3 ][ -5 -3 -2 ]

#> A.maxentryk; ans = 3#> (i,j) = A.ij(ans);

119

Page 120: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

i = 3 j = 1

---------------------------------------------------------------------- matrix A.mean // column-first operation----------------------------------------------------------------------mean elements

#> A = [ 0,-1,2; 1,2,-4; 5,-3,-4 ] ; A =[ 0 -1 2 ][ 1 2 -4 ][ 5 -3 -4 ]

#> A.mean; ans = [ 2 -0.666667 -2 ]

#> A.mean.mean; ans = [ -0.222222 ]

#> A().mean; ans = [ -0.222222 ]

---------------------------------------------------------------------- double p.mean----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

returns ∑i=0

n

ai /(n+1)

#> p = .[ -5,2,4 ] ; p = poly( 4 2 -5 ) = -5x^2 +2x +4#> p .mean ;

ans = 0.33333333

---------------------------------------------------------------------- double .min(double x1, double x2, ... ) // dot-only----------------------------------------------------------------------minimum of arguments

#> .min(4,3); ans = 3

120

Page 121: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> .min(4,3,2); ans = 2

#> .min(4,3,2,1); ans = 1

---------------------------------------------------------------------- matrix A.min // column-first operation

double A.min1 // equivalent to A.min.min(1)----------------------------------------------------------------------minimum elements

#> A = [ 0,-1,2; 1,2,-4; 5,-3,-4 ] ; A =[ 0 -1 2 ][ 1 2 -4 ][ 5 -3 -4 ]

#> A.min; ans = [ 0 -3 -4 ]

#> A.min.min; ans = [ -4 ]

#> A().min; ans = [ -4 ]

#> A.min1; ans = -4

---------------------------------------------------------------------- double p.min----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

returns min \{ai \}

#> p = .[ -5,2,4 ] ; p = poly( 4 2 -5 ) = -5x^2 +2x +4

#> p .min ; ans = -5

---------------------------------------------------------------------- double A.min1k/mink

121

Page 122: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------#> A = [ 3,-1,2; 2,4,-3; -5,-3,-2 ] ; A = [ 3 -1 2 ] [ 2 4 -3 ] [ -5 -3 -2 ]

#> A.min1k; ans = 3

---------------------------------------------------------------------- double A.minentry ----------------------------------------------------------------------absolute minimum element

#> A = [ 0,-1,2; 1,2,-4; 5,-3,-4 ] ; A =[ 0 -1 2 ][ 1 2 -4 ][ 5 -3 -4 ]

#> A.minentry; ans =

---------------------------------------------------------------------- double p.minentry ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

returns min \{|a i |\}

#> p = .[ -5,2,4 ] ; p = poly( 4 2 -5 ) = -5x^2 +2x +4

#> p .minentry ; ans = 2

---------------------------------------------------------------------- double A.minentryk----------------------------------------------------------------------linear index k for A.minentry

#> A = [ 3,-1,2; 2,4,-3; -5,-3,-2 ] ; A =[ 3 -1 2 ]

122

Page 123: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 2 4 -3 ][ -5 -3 -2 ]

#> A.minentryk; ans = 4#> (i,j) = A.ij(ans);

i = 1 j = 2

---------------------------------------------------------------------- matrix A.minor(double i, double j)----------------------------------------------------------------------eliminates i-th row and j-th column

A=[a11 a12 a13

a21 a22 a23

a31 a32 a33] , A .minor (2,1 )=A21=[a12 a13

a32 a33]#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.minor(2,3); ans = [ 1 4 10 ] [ 3 6 12 ]

---------------------------------------------------------------------- double A.mn ----------------------------------------------------------------------return mn for an m×n matrix A

#> A = (1:6)._3; A.mn; A = [ 1 3 5 ] [ 2 4 6 ] ans = 6

---------------------------------------------------------------------- double .mod (double a, double b) // dot-only matrix .mod (double a, matrix b) matrix .mod (matrix a, double b) matrix .mod (matrix a, matrix b)

123

Page 124: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------a % b, remainder r of b = aq + r is equal to modulus a-b*floor(a/b)

#> -13 % 5 ; 13 % 5 ; ans = 2 ans = 3

#> .mod(-13,5); .mod(13,5); // a-b*floor(a/b) ans = 2 ans = 3

#> .rem(-13,5); .rem(13,5); // a-b*fix(a/b) ans = -3 ans = 3

---------------------------------------------------------------------- poly p.monic----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .monic=¿¿

#> p = poly( 1,2,3,4,5 ) ; p = poly( 1 2 3 4 5 ) = 5x^4 +4x^3 +3x^2 +2x +1

#> p .monic; ans = poly( 0.2 0.4 0.6 0.8 1 ) = x^4 +0.8x^3 +0.6x^2 +0.4x +0.2

---------------------------------------------------------------------- matrix A.mul(double i, double s) ----------------------------------------------------------------------elementary row operation, R_i = R_i * s

A=[ Ri

⋯R j

] where Ri is i-th row. A.mul(i,s) = [sR i

⋯R j

] #> A = [ 2,1,4 ; -1,3,5 ]; A = [ 2 1 4 ] [ -1 3 5 ]

#> A.mul(2, 7); ans = [ 2 1 4 ]

124

Page 125: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ -7 21 35 ]

[ N ]

----------------------------------------------------------------------Spherical Bessel Function double .n_(double nu)(double x) dot-only matrix .n_(double nu)(matrix x) matrix .n_(matrix nu)(double x) matrix .n_(matrix nu)(matrix x) ----------------------------------------------------------------------

nn ( x )=(−1 )n+1√ π2x

J−n−1 / 2(x)

n0 ( x )=−cos xx

#> .n_0(0.5); -cos(0.5)/0.5; ans = -1.7551653 ans = -1.7551651

#> .n_0( [0.5, 1] ); ans = [ -1.75517 -0.540302 ]

#> .n_[0;1]( [0.5, 1] ); ans = [ -1.75517 -0.540302 ] [ -4.46918 -1.38177 ]

---------------------------------------------------------------------- double p.n ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .n=n#> p = (1:5).dpoly; p = poly( 5 4 3 2 1 ) = x^4 +2x^3 +3x^2 +4x +5

#> p.n; ans = 4

---------------------------------------------------------------------- double A.n----------------------------------------------------------------------

125

Page 126: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

return n for an m×n matrix A

#> A = (1:6)._3; A.n; A = [ 1 3 5 ] [ 2 4 6 ] ans = 3

---------------------------------------------------------------------- double .ncr (double x, double y) // dot-only matrix .ncr (double a, matrix b) matrix .ncr (matrix a, double b) matrix .ncr (matrix a, matrix b)----------------------------------------------------------------------Combination

nCr=n !

(n−r )! r !

#> .ncr(7,3); // (7)(6)(5)/((3)(2)(1)) ans = 35

---------------------------------------------------------------------- double nextpow2(double x) matrix nextpow2(matrix x) ----------------------------------------------------------------------

nextpow 2 ( x )=n ,2n≥∨x∨¿

#> nextpow2(7); nextpow2(9); // 2^3 = 8 ans = 3 ans = 4

#> nextpow2([7,9]); ans = [ 3 4 ]

---------------------------------------------------------------------- double p.newton(matrix x) ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .newton (x )=a0+a1 (x−x1 )+a2 (x−x1 ) (x−x2 )+…

%> 1 + 2(x-3) + 3(x-3)(x-4) + 4(x-3)(x-4)(x-5)#> poly(1,2,3,4) .newton( [3,4,5] ); ans = poly( -209 169 -45 4 ) = 4x^3 -45x^2 +169x -209

126

Page 127: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> 1 + 2*[3].roots + 3*[3,4].roots + 4*[3,4,5].roots ; ans = poly( -209 169 -45 4 ) = 4x^3 -45x^2 +169x -209

#> 1 + 2*.[1,-3] + 3*.[1,-3]*.[1,-4] + 4*.[1,-3]*.[1,-4]*.[1,-5] ; ans = poly( -209 169 -45 4 ) = 4x^3 -45x^2 +169x -209

---------------------------------------------------------------------- double .norm1(double x1,x2, … ) // dot-only----------------------------------------------------------------------

|x1|+|x2|+|x3|+⋯+|xn|

#> .norm1( -1,2,-3, -4 ); ans = 10

---------------------------------------------------------------------- double .norm2(double x1,x2, … ) // dot-only double hypot(double x1,x2, … )----------------------------------------------------------------------

(x12+x2

2+ x32+⋯+xn

2 )12

#> .norm2( -1,2,-3, -4 ); // equal to "hypot" ans = 5.4772256

---------------------------------------------------------------------- double .norm22(double x1,x2, … ) // dot-only----------------------------------------------------------------------

x12+ x2

2+x32+⋯+xn

2

#> .norm22( -1,2,-3, -4 ); ans = 30

---------------------------------------------------------------------- double A.norm(double p) ----------------------------------------------------------------------p-norm (vector or matrix)

|| A | |p=maxx≠ 0

|| Ax | |p|| x || p

available only for a vector. under development

----------------------------------------------------------------------

127

Page 128: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

double A.norm1 ----------------------------------------------------------------------

|| A | |1=max1≤ j≤ n

∑i=1

m

| aij | // column sum

#> A = [ 1,2,3; 4,5,6; 7,8,9 ];A = [ 1 2 3 ] [ 4 5 6 ] [ 7 8 9 ]

#> A.norm1; // case of matrix ans = 18

#> A().norm1 ; // case of vector ans = 45

---------------------------------------------------------------------- double A.norm2 ----------------------------------------------------------------------

|| A | |F=(∑i=1

m

∑j=1

n

|aij |2)

1 /2

Frobenius norm, sqrt(A**A)

#> A = [ 1,2; 3,4 ]; A = [ 1 2 ] [ 3 4 ]

#> A.norm2; // sqrt( 1^2 +2^2 + 3^2 + 4^2 ) = sqrt(30) ans = 5.4772256

---------------------------------------------------------------------- double A.norm22 ----------------------------------------------------------------------

∑i=1

m

∑j=1

n

|aij |2

A.norm22 = A.norm2 * A.norm2 = A**A

#> A = [ 2,1,4 ; -1,3,5 ]; A = [ 1 2 ] [ 3 4 ]

128

Page 129: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.norm22; // 1^2 +2^2 + 3^2 + 4^2 = 30 ans = 30

---------------------------------------------------------------------- double A.norminf ----------------------------------------------------------------------

|| A | |∞=max1≤ i≤ n

∑j=1

n

|aij | // row sum

infinite-norm

#> A = [ 1,2,3; 4,5,6; 7,8,9 ];A = [ 1 2 3 ] [ 4 5 6 ] [ 7 8 9 ] #> A.norminf; // case of matrix ans = 24

---------------------------------------------------------------------- double .npr (double x, double y) // dot only matrix .npr (double a, matrix b) matrix .npr (matrix a, double b) matrix .npr (matrix a, matrix b)----------------------------------------------------------------------Permutation

nP r=n!

(n−r ) !

#> .npr(7,3); // (7)(6)(5) ans = 210

[ O ]

---------------------------------------------------------------------- poly p.odd ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .odd=a1 x+a3 x3+a5 x

5+a7 x7+…

129

Page 130: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> p = poly( 1,2,3,4,5,6,7 ) ; p = poly( 1 2 3 4 5 6 7 ) = 7x^6 +6x^5 +5x^4 +4x^3 +3x^2 +2x +1

#> p .odd; ans = poly( 0 2 0 4 0 6 ) = 6x^5 +4x^3 +2x

---------------------------------------------------------------------- void .off // dot-only----------------------------------------------------------------------.off 'dot-off' default mode

both 'ones' and '.ones' work

---------------------------------------------------------------------- void .on // dot-only----------------------------------------------------------------------.on 'dot-on' mode

activates dot function only.

---------------------------------------------------------------------- matrix .ones(double m, double n = m)----------------------------------------------------------------------all-ones matrix

#> .ones(2,4); ans = [ 1 1 1 1 ] [ 1 1 1 1 ]

#> .ones(3); [ 1 1 1 ] [ 1 1 1 ] [ 1 1 1 ] ---------------------------------------------------------------------- vertex cs.org ----------------------------------------------------------------------The origin of a coordinate system

#> cs1 = csys.rec ;cs1 = 'rec' local csys org = < 0 0 0 > dir = [ 1 0 0 ] [ 0 1 0 ]

130

Page 131: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 0 0 1 ]

#> cs1.org ; ans = < 0 0 0 >

#> cs1.dir ; ans = [ 1 0 0 ] [ 0 1 0 ] [ 0 0 1 ]

[ P ]

---------------------------------------------------------------------- double .P_n(double x) dot-only matrix .P_n(matrix x), for real-part only----------------------------------------------------------------------Legendre polynomial

#> .P_5(0.3); ans = 0.34538625

#> .P_5( [0.3,0.4] ); ans = [ 0.345386 0.27064 ]

#> .hold; for.n(1,5) plot.x(-1,1) ( .P_n(x) ); plot;

---------------------------------------------------------------------- poly poly.P(double n) ----------------------------------------------------------------------Legendre polynomial of degree n

P0 ( x )=1 ,P1 ( x )=xPn ( x )=(1 / n ) [ (2n−1 ) x Pn−1 ( x )−(n−1 )Pn−2(x )]

131

Page 132: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

This command is for finding a polynomial itself. For evaluation, it is more convenient to use

.P_n(x)

#> for.n(0,5) poly.P(n); ans = poly( 1 )

= 1 ans = poly( 0 1 ) = x ans = poly( -0.5 0 1.5 ) = 1.5x^2 -0.5 ans = poly( -0 -1.5 0 2.5 ) = 2.5x^3 -1.5x ans = poly( 0.375 -0 -3.75 0 4.375 ) = 4.375x^4 -3.75x^2 +0.375 ans = poly( 0 1.875 -0 -8.75 0 7.875 ) = 7.875x^5 -8.75x^3 +1.875x

#> .hold; for.n(0,5) plot.x(-1,1) ( .P_n(x) ); plot;

---------------------------------------------------------------------- matrix A.pass ----------------------------------------------------------------------a line passing two pointsa parabola passing three pointsa cubic passing four points

#> [ 1,1, 2,3 ].pass; y = 2x - 1, root = 0.5

#> [ 1,1, 2,3, 3,7 ].pass; y = x^2 - x + 1 roots [ 0.5 - i 0.866025 ] [ 0.5 + i 0.866025 ] vertex at ( 0.5, 0.75 ) y_minimum = 0.75 y-axis intersect ( 0, 1 ) symmetry at x = 0.5 directrix at y = 0.5

132

Page 133: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

focus at ( 0.5, 1 )

#> [ 1,1, 2,3, 3,7, 5,16 ].pass; y = -0.208333x^3 + 2.25x^2 - 3.29167x + 4.25 y = (1/24)*( -5x^3 + 54x^2 - 79x + 102 ) roots [ 9.34253 ] [ 0.728734 - i 1.2855 ] [ 0.728734 + i 1.2855 ] local minima ( 0.826314, 2.9488 ) local maxima ( 6.37369, 20.7312 ) inflection pt. ( 3.6, 11.84 ) y-axis intersect ( 0, 4.25 )

---------------------------------------------------------------------- void csys.pass0 // pass through -x coordinate, 0 <= t < 2*pi void csys.pass180 // pass through +x coordinate, -pi < t <= pi----------------------------------------------------------------------#> csys.pass180; < 1, -1, 0 >.cyl ; ans = < 1.414 5.498 0 >

#> csys.pass0; < 1, -1, 0 >.cyl ; ans = < 1.414 -0.7854 0 >

---------------------------------------------------------------------- matrix A.pcent ----------------------------------------------------------------------a_ij/sum(a_ij) * 100

A=(aij ) ,( aija11+a12+…+a21+…+amn )×100

#> A = [ 3, 4; 7, 6 ]; A = [ 3 4 ] [ 7 6 ]#> A.pcent; ans = [ 15 20 ] [ 35 30 ]#> ans.sum1; ans = 100

---------------------------------------------------------------------- figure A.plot ----------------------------------------------------------------------plot

133

Page 134: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- (matrix P, matrix L, matrix U) = A.plu // tuple----------------------------------------------------------------------A = PLU decomposition

#> A = [ 0,2,1; 3,2; 4,8,-16 ]; (P,L,U) = A.plu; A = [ 0 2 1 ] [ 3 2 0 ] [ 4 8 -16 ] P = [ 0 0 1 ] [ 0 1 0 ] [ 1 0 0 ] L = [ 1 0 0 ] [ 0.75 1 0 ] [ 0 -0.5 1 ] U = [ 4 8 -16 ] [ 0 -4 12 ] [ 0 0 7 ]

---------------------------------------------------------------------- double .pm (double x) dot-only matrix .pm (matrix A) double x .pm----------------------------------------------------------------------

cos πn¿ (−1 )n#> .pm(0); .pm(1); .pm(2); 2.pm; ans = 1 ans = -1 ans = 1 ans = 1

#> .pm( [0,1,2] ); ans = [ 1 -1 1 ]

---------------------------------------------------------------------- matrix A.pm ----------------------------------------------------------------------alternating signs (plus and minus) by (−1 )i+ jaij

#> A = (1:20)._5; A = [ 1 5 9 13 17 ] [ 2 6 10 14 18 ]

134

Page 135: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 3 7 11 15 19 ] [ 4 8 12 16 20 ]

#> A.pm; ans = [ 1 -5 9 -13 17 ] [ -2 6 -10 14 -18 ] [ 3 -7 11 -15 19 ] [ -4 8 -12 16 -20 ]

---------------------------------------------------------------------- poly p.pm----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p . pm=a0−a1 x+a2 x2−a3 x

3+…+(−1 )nan xn

#> p = .[ 1,2,3,4,5 ]; p = poly( 5 4 3 2 1 ) = x^4 +2x^3 +3x^2 +4x +5

#> p .pm ; // actually cos(n*pi) = (-1)^n ans = poly( 5 -4 3 -2 1 ) = x^4 -2x^3 +3x^2 -4x +5

---------------------------------------------------------------------- poly .polyfit(matrix X, matrix Y, double kth)----------------------------------------------------------------------polynomial regression

#> x = [ 1,2,3,4 ]; y = [ 2,3,5,9 ]; x = [ 1 2 3 4 ] y = [ 2 3 5 9 ]

#> .polyfit(x,y,1); ans = poly( -1 2.3 ) = 2.3x -1

#> .polyfit(x,y,2); ans = poly( 2.75 -1.45 0.75 ) = 0.75x^2 -1.45x +2.75

#> .polyfit(x,y,3); ans = poly( 1 1.33333 -0.5 0.166667 ) = 0.166667x^3 -0.5x^2 +1.33333x +1

#> .polyfit(x,y,1).plot(1,4);#> plot+(x,y);

135

Page 136: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------Power of a real number double pow (double a, double b) matrix pow (double a, matrix b) matrix pow (matrix a, double b) matrix pow (matrix a, matrix b)----------------------------------------------------------------------

pow (a ,b )=ab#> pow(3,2); // 3^2 ans = 9

---------------------------------------------------------------------- poly p.pow(double k) ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p . pow (k )=a0+a1 xk+a2 x

2k+a3 x3k…+an x

nk

#> p = .[ 1,2,3,4,5 ]; p = poly( 5 4 3 2 1 ) = x^4 +2x^3 +3x^2 +4x +5

#> p .pow(3) ; // replace x by x^3ans = poly( 5 0 0 4 0 0 3 0 0 2 0

0 1 ) = x^12 +2x^9 +3x^6 +4x^3 +5

---------------------------------------------------------------------- double pow2(double x) matrix pow2(matrix x) ----------------------------------------------------------------------

pow 2 ( x )=2x#> pow2(10); ans = 1024

136

Page 137: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- double pow10(double x) matrix pow10(matrix x) ----------------------------------------------------------------------

pow 10 (x )=10x#> pow10(2); ans = 100

---------------------------------------------------------------------- matrix .primes (double a, double b) ----------------------------------------------------------------------primes numbers between a and b

#> .primes(10,100); ans = [ 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 ]

---------------------------------------------------------------------- matrix A.prod // column-first operation double A.prod1 // equivalent to A.prod.prod(1) ----------------------------------------------------------------------product of elements

#> A = [ 1,-1,2; 1,2,-4; 5,-3,-4 ] ; A =[ 1 -1 2 ][ 1 2 -4 ][ 5 -3 -4 ]

#> A.prod; ans = [ 5 6 32 ]

#> A().prod; ans = [ 960 ]

#> A.prod1; ans = 960

---------------------------------------------------------------------- double p.prod ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .∏ ¿a0a1a2a3×…×an

137

Page 138: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> p = .[ -5,2,4 ] ; p = poly( 4 2 -5 ) = -5x^2 +2x +4#> p .prod ;

ans = -40

---------------------------------------------------------------------- double .psi(double x) dot only matrix .psi(matrix x) ----------------------------------------------------------------------

ψ (1 )=−γ ,ψ (n>1 )=−γ+11+ 1

2+ 1

3+⋯+ 1

n−1

#> .psi( 1:10 ); ans = [ -0.577216 0.422784 0.922784 1.25612 1.50612 1.70612 1.87278 2.01564 2.14064 2.25175 ]

---------------------------------------------------------------------- matrix A.pushd ----------------------------------------------------------------------push-down with top row

#> A = (1:20)._5; A = [ 1 5 9 13 17 ] [ 2 6 10 14 18 ] [ 3 7 11 15 19 ] [ 4 8 12 16 20 ]

#> A.pushd; ans = [ 1 0 0 0 0 ] [ 2 5 0 0 0 ] [ 3 6 9 0 0 ] [ 4 7 10 13 0 ]

---------------------------------------------------------------------- matrix A.pushl ----------------------------------------------------------------------push-left with rightmost column

#> A = (1:20)._5; A = [ 1 5 9 13 17 ] [ 2 6 10 14 18 ] [ 3 7 11 15 19 ] [ 4 8 12 16 20 ]

138

Page 139: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.pushl; ans = [ 1 5 9 13 17 ] [ 6 10 14 18 0 ] [ 11 15 19 0 0 ] [ 16 20 0 0 0 ]

---------------------------------------------------------------------- matrix A.pushr ----------------------------------------------------------------------push-right with leftmost column

#> A = (1:20)._5; A = [ 1 5 9 13 17 ] [ 2 6 10 14 18 ] [ 3 7 11 15 19 ] [ 4 8 12 16 20 ]

#> A.pushr; ans = [ 1 5 9 13 17 ] [ 0 2 6 10 14 ] [ 0 0 3 7 11 ] [ 0 0 0 4 8 ]

---------------------------------------------------------------------- matrix A.pushu ----------------------------------------------------------------------push-up with bottom row

#> A = (1:20)._5; A = [ 1 5 9 13 17 ] [ 2 6 10 14 18 ] [ 3 7 11 15 19 ] [ 4 8 12 16 20 ]

#> A.pushu; ans = [ 1 6 11 16 0 ] [ 2 7 12 0 0 ] [ 3 8 0 0 0 ] [ 4 0 0 0 0 ]

[ Q ]

139

Page 140: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- (matrix Q, matrix R) = A.qr // tuple----------------------------------------------------------------------A = QR decomposition

#> A = [ 1,-1,3; 1,-1,-2; 0,1,1 ]; A = [ 1 -1 3 ] [ 1 -1 -2 ] [ 0 1 1 ]

#> (Q,R) = A.qr;; Q.trun10; R.trun10; ans = [ 0.707107 0 0.707107 ] [ 0.707107 0 -0.707107 ] [ 0 1 0 ] ans = [ 1.41421 -1.41421 0.707107 ] [ 0 1 1 ] [ 0 0 3.53553 ]

matrix user_qr(matrix& A) { n = A.m; Q = A.unit; S = .I(n);

for.i(2,n) { x = Q.col(i-1); S -= x * x.tr; Q.col(i) = ( S * Q.col(i) ).unit.trun12; } return Q; }

#> sqrt(2)*user_qr(A); // user function listed above ans = [ 1 0 1 ] [ 1 0 -1 ] [ 0 1.41421 0 ]

---------------------------------------------------------------------- poly p.quad(double r, double s)----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

divisor x2+rx+s by Bairstow method

#> .[1,12,62,172,221] .quad(0,0); // starting from x^2 ans = poly( 13 4 1 )

140

Page 141: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

= x^2 +4x +13// internal iteration by the Bairstow method is as follows Iter r s

[ 0 0 0 ] [ 1 2.08429 3.56452 ] [ 2 3.65639 7.37287 ] [ 3 4.75654 12.2209 ] [ 4 3.70532 12.7884 ] [ 5 3.97725 12.9056 ] [ 6 4.00016 12.9994 ] [ 7 4 13 ] [ 8 4 13 ]

[ R ]

---------------------------------------------------------------------- double v.R // both read/write double v.P double v.T ----------------------------------------------------------------------%> spherical coordinate ------------------------------------------------#> v = < 1,1,1 > ; v = < 1 1 1 >

#> v.R; v.P; v.T; ans = 1.7320508 ans = 0.95531662 ans = 0.78539816

#> v.P += 1; v.R; v.P; v.T; // only P is changed v = < 1.135 1.135 -0.6497 > ans = 1.7320508 ans = 1.95531662 ans = 0.78539816

---------------------------------------------------------------------- double z.r // both read/write double z.t ----------------------------------------------------------------------z.r |z| = sqrt(x*x+y*y)z.t arg = atan(y/x)z.deg deg = atan(y/x)*180/pi

#> z = 3+4!;z = 3 + 4!

141

Page 142: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> z.r = 10; z;ans = 10z = 6 + 8!

#> z = 3+4!; z = 3 + 4!

#> z.t = pi/2; z;ans = 1.5707963z = 3.06152e-016 + 5!

---------------------------------------------------------------------- double v.r // both read/write double v.t ----------------------------------------------------------------------%> cylindrical coordinate ----------------------------------------------#> v = < 1,1,1 > ; v = < 1 1 1 >

#> v.r; v.t; v.z; ans = 1.4142136 ans = 0.78539816 ans = 1

#> v.r += 1; v.r; v.t; v.z; // only r is changed v = < 1.707 1.707 1 > ans = 2.4142136 ans = 0.78539816 ans = 1

---------------------------------------------------------------------- void csys.rad void csys.deg ----------------------------------------------------------------------angles in the degree system

#> csys.deg; < 1, 45, 0, cyl > ; ans = < 0.7071 0.7071 0 >

#> csys.rad; < 1, pi/4, 0, cyl > ; ans = < 0.7071 0.7071 0 >

---------------------------------------------------------------------- matrix .rand (double m, double n = m)

142

Page 143: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------random number matrix

#> .rand(3,4);

ans = [ 0.00041 0.265 0.11478 0.24464 ] [ 0.18467 0.19169 0.29358 0.05705 ] [ 0.06334 0.15724 0.26962 0.28145 ]

---------------------------------------------------------------------- double A.rank---------------------- ------------------------------------------------rank of a matrix A

%> rank of a matrix#> A = [ 1,2; -1,-2; 2,4 ]; A.rank;A =[ 1 2 ][ -1 -2 ][ 2 4 ]ans = 1

#> A = [ 1,-1,2; 2,-2,4 ]; A.rank;A =[ 1 -1 2 ][ 2 -2 4 ]ans = 1

#> A = [ 1,-1,2; 2,-2,3 ]; A.rank;A =[ 1 -1 2 ][ 2 -2 3 ]ans = 2

---------------------------------------------------------------------- matrix A.ratio(double denom=10000) ----------------------------------------------------------------------shows a rational approximation

#> A = matrix.hilb(4);

A = [ 1 0.5 0.333333 0.25 ] [ 0.5 0.333333 0.25 0.2 ] [ 0.333333 0.25 0.2 0.166667 ] [ 0.25 0.2 0.166667 0.142857 ]

143

Page 144: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.ratio; (1/420) x [ 420 210 140 105 ] [ 210 140 105 84 ] [ 140 105 84 70 ] [ 105 84 70 60 ]

---------------------------------------------------------------------- poly p.ratio ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p . ratio=( 1lcm )(b¿¿0+b1 x+b2 x

2+b3 x3+…+bn x

n)¿

shows a rational approximation

#> p = .[ 1/2, 1/3, 1/4, 1/5 ]; p = poly( 0.2 0.25 0.333333 0.5 ) = 0.5x^3 +0.333333x^2 +0.25x +0.2

#> p .ratio ; ans = (1/60) * poly( 12 15 20 30 )

---------------------------------------------------------------------- double A.ratio1 ----------------------------------------------------------------------denomenator of a rational approximation

#> A = matrix.hilb(4); A = [ 1 0.5 0.333333 0.25 ] [ 0.5 0.333333 0.25 0.2 ] [ 0.333333 0.25 0.2 0.166667 ] [ 0.25 0.2 0.166667 0.142857 ]

#> A.ratio1; ans = 420

#> A.ratio; (1/420) x [ 420 210 140 105 ] [ 210 140 105 84 ] [ 140 105 84 70 ] [ 105 84 70 60 ]

---------------------------------------------------------------------- matrix A.read(string fname) ----------------------------------------------------------------------read A from a file

144

Page 145: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- matrix W.real // both read/write----------------------------------------------------------------------real part

#> A = [ 1-2i, -3+4i; 2+3i, 5+2i ]; A = [ 1 - i 2 -3 + i 4 ] [ 2 + i 3 5 + i 2 ]

#> A.real; ans = [ 1 -3 ] [ 2 5 ]

#> A.real += 100; A = [ 101 - i 2 97 + i 4 ] [ 102 + i 3 105 + i 2 ]

---------------------------------------------------------------------- vertex v.rec ----------------------------------------------------------------------read in rectangular coordinate

#> < 1,1,1 > .rec ; ans = < 1 1 1 >

---------------------------------------------------------------------- csys csys.rec ----------------------------------------------------------------------a rectangular coordinate system

#> cs1 = csys.rec ;cs1 = 'rec' local csys org = < 0 0 0 > dir = [ 1 0 0 ] [ 0 1 0 ] [ 0 0 1 ]

---------------------------------------------------------------------- matrix .regress(matrix X, matrix Y, double kth) matrix .regress(matrix X, matrix Y, matrix f(double x))----------------------------------------------------------------------

145

Page 146: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

regression curve

U=[u1(x1) u1(x2) ⋯u2(x1) u2(x2) ⋯

⋯ u1(xn)⋯ u2( xn)

⋮ ⋮ ⋮ur(x1) ur(x2) ⋯

⋮ ⋮⋯ ur (xn)

] , a=[a1

a2

⋮ar

] , f=[f 1

f 2

⋮⋮f n

]UUT a=Uf

#> x = [ 1,2,3,4 ]; f = [ 2,3,5,9 ]; x = [ 1 2 3 4 ] f = [ 2 3 5 9 ]

#> matrix mftn(double x) = [ 1 ; exp(0.4*x) ]; // base functions#> a = .regress(x,f, mftn); // built-in dot function a = [ -1.37806 2.0443 ]

f ( x )=−1.378061+2.044303 e0.4 x

#> mftn++(x); // matrix(double) can be upgraded by ++ postfix ans = [ 1 1 1 1 ] [ 1.49182 2.22554 3.32012 4.95303 ]

U=[ 1 1e0.4 x1 e0.4x2

1 1e0.4x3 e0.4 x4]

#> F = a * mftn++(x); // fitted values F = [ 1.67168 3.17162 5.40926 8.74744 ]

#> .corrcoef(f,F); // correlation coefficient ans = 0.99357009

---------------------------------------------------------------------- double .rem (double a, double b) // dot-only matrix .rem (double a, matrix b) matrix .rem (matrix a, double b) matrix .rem (matrix a, matrix b)----------------------------------------------------------------------remainder a-b*fix(a/b)

#>.rem(-13,5); .rem(13,5); // a-b*fix(a/b) ans = -3 ans = 3

#>.mod(-13,5); .mod(13,5); // a-b*floor(a/b)

146

Page 147: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

ans = 2 ans = 3

---------------------------------------------------------------------- matrix A.repmat(double m, double n=m) ----------------------------------------------------------------------extends a p×q matrix to m p×nq matrix by tile-shaped copying

#> matrix.format("%5g"); matrix.maxcol(20):#> A = [ 1,2,3; 4,5 ]; A = [ 1 2 3 ] [ 4 5 0 ]

#> A.repmat(3,4); ans = [ 1 2 3 1 2 3 1 2 3 1 2 3 ] [ 4 5 0 4 5 0 4 5 0 4 5 0 ] [ 1 2 3 1 2 3 1 2 3 1 2 3 ] [ 4 5 0 4 5 0 4 5 0 4 5 0 ] [ 1 2 3 1 2 3 1 2 3 1 2 3 ] [ 4 5 0 4 5 0 4 5 0 4 5 0 ]

---------------------------------------------------------------------- matrix A.resize(double m, double n)----------------------------------------------------------------------A p×q matrix becomes a m×n matrix by resizing.

#> A = [ 1,2,3; 4,5,6 ]; A = [ 1 2 3 ] [ 4 5 6 ]

#> A.resize(4,6); ans = [ 1 2 3 0 0 0 ] [ 4 5 6 0 0 0 ] [ 0 0 0 0 0 0 ] [ 0 0 0 0 0 0 ]

#> A.resize(4,2); ans = [ 1 2 ] [ 4 5 ] [ 0 0 ] [ 0 0 ]

147

Page 148: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.resize(1,5); ans = [ 1 2 3 0 0 ]

---------------------------------------------------------------------- matrix A.rev ----------------------------------------------------------------------reverse elements, rotating 180 degree

A=[a1 a4 a7 a10

a2 a5 a8 a11

a3 a6 a9 a12] , A . rev=[a12 a9 a6 a3

a11 a8 a5 a2

a10 a7 a4 a1]

#> A = (1:6)._2; A = [ 1 4 ] [ 2 5 ] [ 3 6 ]

#> A.rev; ans = [ 6 3 ] [ 5 2 ] [ 4 1 ]

---------------------------------------------------------------------- poly p.rev----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn+…

p . rev=an+an−1 x+an−2 x2+an−3x

3+…+a0 xn

#> p = .[ 1,2,3,4,5 ] ; p = poly( 5 4 3 2 1 ) = x^4 +2x^3 +3x^2 +4x +5

#> p .rev ; ans = poly( 1 2 3 4 5 ) = 5x^4 +4x^3 +3x^2 +2x +1

---------------------------------------------------------------------- void poly.right(string fmt) ----------------------------------------------------------------------set the right delimiter for screen output

#> p = poly( 1,2,3 ) ; p = poly( 1 2 3 ) = 3x^2 +2x +1

148

Page 149: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> poly.right ("[]()left<>--->") ; p ; p = poly( 1 2 3 []()left<>---> = 3x^2 +2x +1

---------------------------------------------------------------------- matrix A.rot90 ----------------------------------------------------------------------rotate 90 degree (counter-clockwise)

A=[a1 a4 a7 a10

a2 a5 a8 a11

a3 a6 a9 a12] , A . rot 90=[a10 a11 a12

a7 a8 a9

a4 a5 a6

a1 a2 a3]

#> A = [ 1,2; 3,4; 5,6 ]; A = [ 1 2 ] [ 3 4 ] [ 5 6 ]

#> A.rot90 ; ans = [ 2 4 6 ] [ 1 3 5 ]

---------------------------------------------------------------------- matrix A.rotm90 ----------------------------------------------------------------------

A=[a1 a4 a7 a10

a2 a5 a8 a11

a3 a6 a9 a12] , A . rotm90=[ a3 a2 a1

a6 a5 a4

a9 a8 a7

a12 a11 a10]

#> A = [ 1,2; 3,4; 5,6 ]; A = [ 1 2 ] [ 3 4 ] [ 5 6 ]

#> A.rotm90; ans = [ 5 3 1 ] [ 6 4 2 ]

149

Page 150: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- poly .roots (double x1,x2, ..., xn) dot-only poly .roots (matrix A);----------------------------------------------------------------------polynomial with given roots

#> A = [ 1+1!; 1-1! ]; // 1! = 1i = 1j for digits A = [ 1 + i 1 ] [ 1 - i 1 ]

#> .roots(A); // complex roots ans = poly( 2 -2 1 ) = x^2 -2x +2

---------------------------------------------------------------------- poly A.roots ----------------------------------------------------------------------(x-x1)(x-x2) ... (x-xn)

#> A = [ 0,1,2,3 ]; A = [ 0 1 2 3 ]

#> A.roots; ans = poly( 0 -6 11 -6 1 ) = x^4 -6x^3 +11x^2 -6x

---------------------------------------------------------------------- double .round (double x) matrix .round (matrix A) ----------------------------------------------------------------------integer near x

#> .round(pi); ans = 3

#> .round( [pi, -pi] ); ans = [ 3 -3 ]

---------------------------------------------------------------------- double x.round matrix A.round poly p.round ----------------------------------------------------------------------integer near x

150

Page 151: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> pi.round; ans = 3

#> (-pi).round; ans = -3

For a polynomial and a matrix, element-by-element operation is applied.

---------------------------------------------------------------------- matrix W.row(i) // equivalent to W(i,*)----------------------------------------------------------------------i-th row vector

Note that this function allows to modify the original matrix.

#> A = (1:12)._4 ; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.row(2); ans = [ 2 5 8 11 ]

#> A.row(2) += 100; A = [ 1 4 7 10 ] [ 102 105 108 111 ] [ 3 6 9 12 ]

---------------------------------------------------------------------- matrix A.rowabs ----------------------------------------------------------------------finds Euclidean norm of each row

#> A = [ 1,2; 3,4 ]; A = [ 1 2 ] [ 3 4 ]

#> A.rowabs; // [ sqrt(1+4); sqrt(9+16) ] ans = [ 2.23607 ] [ 5 ]

---------------------------------------------------------------------- matrix A.rowdel(double i)

151

Page 152: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------delete i-th row

#> A = [ 1,2; 3,4; 5,6 ]; A = [ 1 2 ] [ 3 4 ] [ 5 6 ]

#> A.delrow(2); ans = [ 1 2 ] [ 5 6 ]

---------------------------------------------------------------------- matrix A.rowdet(i) ----------------------------------------------------------------------i-th row determinantConsider the Laplace expansion of a determinant

A=[ a11 a12 a13 a14

a21 a22 a23 a24

a31 a32 a33 a34

a41 a42 a43 a44]

det (A )=∑i=1

n

C ija ij=∑j=1

n

Cij aij ,C ij=(−1 )i+ jdet ( Aij )

Then, det (A ij ) is obtained by A.rowdet(i).

For example, an equation of a circle passing three points

(x¿¿1 , y1), (x¿¿2 , y2) ,(x¿¿3 , y3)¿ ¿¿is given as

det (A )=|x2+ y2 x y 1x1

2+ y12 x1 y1 1

x22+ y2

2 x2 y2 1x3

2+ y32 x3 y3 1

|¿C11( x2+ y2 )+C 12 ( x )+C13 ( y )+C14 (1 )=0

152

Page 153: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

For three points (1,1 ) , (−1,2 ) ,(2,4), we have

#> A = [ 1,1,1,1; 1+1,1,1,1; 1+4,-1,2,1; 4+16,2,4,1 ]; A = [ 1 1 1 1 ] [ 2 1 1 1 ] [ 5 -1 2 1 ] [ 20 2 4 1 ]

#> A.minor(1,1).det; ans = -7#> A.minor(1,2).det; ans = -9#> A.minor(1,3).det; ans = 39#> A.minor(1,4).det; ans = 34#> A.rowdet(1); ans = [ -7 -9 39 34 ]

Therefore, (−1 )1+1 (−7 ) (x2+ y2 )−(−9 ) ( x )+(39 ) ( y )−(34) (1 )=0

#> [ 1,1, -1,2, 2,4 ].circle; // an easier approach circle (-7)(x^2+y^2) + (9)x + (39)y + (-34) = 0 center = ( 0.642857, 2.78571 ) radius = 1.82108 ans = [ -7 9 39 -34 ]

---------------------------------------------------------------------- matrix A.rowend ----------------------------------------------------------------------the last row vector A(end,*), A.endrow

#> A = [ 1,2; 3,4; 5,6 ]; A = [ 1 2 ] [ 3 4 ] [ 5 6 ]

#> A.endrow; ans = [ 5 6 ]

---------------------------------------------------------------------- matrix A.rowins(double i, matrix B) ----------------------------------------------------------------------insert B at i-th row, A.insrow

#> matrix.format("%6g");#> A = (1:16)._4 ;

153

Page 154: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

A =[ 1 5 9 13 ][ 2 6 10 14 ][ 3 7 11 15 ][ 4 8 12 16 ]

#> A.insrow(1, [101:105; 201:205]); // [101:105; 201:205] _ A ans =[ 101 102 103 104 105 ][ 201 202 203 204 205 ][ 1 5 9 13 0 ][ 2 6 10 14 0 ][ 3 7 11 15 0 ][ 4 8 12 16 0 ]

#> A.insrow(2, [101:105; 201:205]');ans =[ 1 5 9 13 ][ 101 201 0 0 ][ 102 202 0 0 ][ 103 203 0 0 ][ 104 204 0 0 ][ 105 205 0 0 ][ 2 6 10 14 ][ 3 7 11 15 ][ 4 8 12 16 ]

#> A.insrow(100, [101:105; 201:205]'); // A _ [101:105; 201:205]'ans =[ 1 5 9 13 ][ 2 6 10 14 ][ 3 7 11 15 ][ 4 8 12 16 ][ 101 201 0 0 ][ 102 202 0 0 ][ 103 203 0 0 ][ 104 204 0 0 ][ 105 205 0 0 ]

---------------------------------------------------------------------- matrix A.rowskip/skip(double k)----------------------------------------------------------------------skip rows by hopping k rows

R1 ,R1+k , R1+2k ,⋯ if k>0

154

Page 155: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

⋯ , Rm−2k ,Rm−k , Rm if k<0

#> A = (1:50)';; #> A.rowskip(10); // from first-row, skip forward ans = [ 1 ] [ 11 ] [ 21 ] [ 31 ] [ 41 ]

#> A.rowskip(-10); // from end-row, skip backward ans = [ 10 ] [ 20 ] [ 30 ] [ 40 ] [ 50 ]

---------------------------------------------------------------------- matrix A.rowswap/swap(double i,double j) ----------------------------------------------------------------------swap rows as an elementary operation

#> A = [ 1,2; 3,4; 5,6; 7,8 ]; A = [ 1 2 ] [ 3 4 ] [ 5 6 ] [ 7 8 ]

#> A.rowswap(2,4); ans = [ 1 2 ] [ 7 8 ] [ 5 6 ] [ 3 4 ]

---------------------------------------------------------------------- matrix A.rowunit ----------------------------------------------------------------------each row is normalized to be unity.

#> A = [ 1,2; 4,3; 2,7 ]; A = [ 1 2 ] [ 4 3 ] [ 2 7 ]

155

Page 156: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A.rowunit; ans = [ 0.447214 0.894427 ] [ 0.8 0.6 ] [ 0.274721 0.961524 ]

[ S ]

---------------------------------------------------------------------- matrix A.sdev // column-first operation----------------------------------------------------------------------standard deviation

#> A = [ 1,2; 4,3; 2,7 ]; A = [ 1 2 ] [ 4 3 ] [ 2 7 ]

#> A.sdev; ans = [ 1.24722 2.16025 ]

#> A().sdev; ans = [ 1.95078 ]

#> A.sdev.sdev; // note that data are different from A() ans = [ 0.456514 ]

----------------------------------------------------------------------Secant Function double sec(double x) complex sec(complex z) matrix sec(matrix A)----------------------------------------------------------------------

sec ( x )= 1cos ( x )

, sec ( x+2π )=sec(x)

−∞<x<∞ ,sec ( x )≤−1,1≤sec ( x )

#> sec( pi/3 ); ans = 2

#> sec( 2i ); ans = 0.265802 + 0!

156

Page 157: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> sec( [ pi/3, 2i ] ); ans = [ 2 0.265802 ]

#> plot.x( 0,pi/2-0.1 )( sec(x) ); #> plot+.x( pi/2+0.1, pi )( sec(x) );

---------------------------------------------------------------------- double .secant(double a, double b, doubel f(double x)) dot-only----------------------------------------------------------------------root-finding by the secant method

#> double f(x) = exp(x)-5;

#> .bisect(3,4, f); // .bisect needs to know f(a)f(b) < 0 .bisect(a,b, f(x)), f(a)*f(b) > 0 ans = 1.#INF

#> .secant(4,5, f); // .secant starts with no condition but may fail ans = 1.6094379

----------------------------------------------------------------------Secant Function in Degree double secd(double x) complex secd(complex z) matrix secd(matrix A)----------------------------------------------------------------------

secd (x )=sec( πx180 ) , secd ( x+360 )=secd (x )

−∞<x<∞ ,secd ( x )≤−1 ,1≤secd ( x )

#> secd( 60 ); ans = 2

#> secd( 2.todeg! ); ans = 0.265802 + 0!

#> secd( [ 60, 2.todeg! ] );

157

Page 158: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

ans = [ 2 0.265802 ]

#> plot.x( 0,89 )( secd(x) ); #> plot+.x( 91,180 )( secd(x) );

----------------------------------------------------------------------Hyperbolic Secant Function double sech(double x) complex sech(complex z) matrix sech(matrix A)----------------------------------------------------------------------

sech ( x )= 1cosh ( x )

−∞<x<∞ ,0<sech ( x )≤1

#> sech( pi ); ans = 0.086266738

#> sech( 2i ); ans = -2.403 + 0!

#> sech( [ pi, 2i ] ); ans = [ 0.0862667 -2.403 ]

#> plot.x( -5,5 ) ( sech(x) );

---------------------------------------------------------------------- poly p.shift(double c) ----------------------------------------------------------------------

158

Page 159: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p . shift ( c )=a0+a1 ( x−c )+a2 ( x−c )2+…+an(x−c)n

replace x in p(x) by x-c

%> p(x) = x^4 + 2x^3 + 3x^2 + 4x + 5%> q(x) = x^4 - 6x^3 + 15x^2 - 16x + 9

#> p = .[ 1,2,3,4,5 ]; p = poly( 5 4 3 2 1 ) = x^4 +2x^3 +3x^2 +4x +5

#> q = p.shift(2); // replace x by x-2 q = poly( 9 -16 15 -6 1 ) = x^4 -6x^3 +15x^2 -16x +9

#> q( .[1,2] ); // confirm p(x) = q(x+2) ans = poly( 5 4 3 2 1 ) = x^4 +2x^3 +3x^2 +4x +5

---------------------------------------------------------------------- double A.shorter ----------------------------------------------------------------------return min(m,n) for an m×n matrix A

#> A = (1:6)._3; A = [ 1 3 5 ] [ 2 4 6 ]

#> A.shorter; // compare with A.longer = 3 ans = 2

---------------------------------------------------------------------- double .sign (double x) matrix .sign(matrix x) ----------------------------------------------------------------------(1) if x>0, (-1) if x<= and (0) if x=0

#> .sign(-3); .sign(0); .sign(5); ans = -1 ans = 0 ans = 1

---------------------------------------------------------------------- double x.sign

159

Page 160: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------(1) if x>0, (-1) if x<= and (0) if x=0

#> ( pi).sign; ans = 1#> ( 0).sign; ans = 0#> (-pi).sign; ans = -1

----------------------------------------------------------------------Sine Function double sin(double x) complex sin(complex z) matrix sin(matrix A)----------------------------------------------------------------------

−∞<x<∞ ,−1≤ sin (x )≤1

#> sin( pi/6 ); ans = 0.5

#> sin( 2i ); ans = 0 + 3.62686!

#> sin( [ pi/6, 2i ] ); ans = [ 0.5 0 + i 3.62686 ]

#> plot.x( -pi/2,pi/2 ) ( sin(x) );

---------------------------------------------------------------------- double sinc(double x) matrix sinc(matrix A)----------------------------------------------------------------------

sin xx

#> sinc ( 0 ); ans = 1

#> sinc ( [ 0, 1 ] ); ans = [ 1 0.841471 ]

160

Page 161: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------Sine Function in Degree double sind(double x) complex sind(complex z) matrix sind(matrix A)----------------------------------------------------------------------

sind ( x )=sin( πx180 )−∞<x<∞ ,−1≤ sind ( x )≤1

#> sind( 30 ); ans = 0.5

#> sind( 2.todeg! ); ans = 0 + 3.62686!

#> sind( [ 30, 2.todeg! ] ); ans = [ 0.5 0 + i 3.62686

#> plot.x( -90,90 ) ( sind(x) );

----------------------------------------------------------------------Hyperbolic Sine Function double sinh(double x) complex sinh(complex z) matrix sinh(matrix A)----------------------------------------------------------------------

sinh ( x )= ex−e− x

2−∞<x<∞ ,−∞<sinh (x )<∞

#> sinh( pi ); ans = 11.548739

#> sinh( 2i ); ans = -0 + 0.909297!

161

Page 162: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> sinh( [ 0.5, 2i ] ); ans = [ 0.521095 -0 + i 0.909297 ]

#> plot.x( -5,5 ) ( sinh(x) );

---------------------------------------------------------------------- double Sint(double x) matrix Sint(matrix x) ----------------------------------------------------------------------

Sint ( x )=1x∫0

x sin ttdt

#> Sint(1); ans = 0.94608307

#> Sint([1,2]); ans = [ 0.946083 0.802706 ]

---------------------------------------------------------------------- (double i, double j) = A.size // tuple----------------------------------------------------------------------double tuple, number of rows and columns

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> (m,n) = A.size; m = 3 n = 4

#> A.m; A.n; ans = 3 ans = 4

---------------------------------------------------------------------- matrix A.skewl(double k)----------------------------------------------------------------------

162

Page 163: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

lower-triangular with respect to the skew-diagonal

#> A = (1:20)._4; A = [ 1 6 11 16 ] [ 2 7 12 17 ] [ 3 8 13 18 ] [ 4 9 14 19 ] [ 5 10 15 20 ]

#> A.skewl(0); ans = [ 0 0 0 16 ] [ 0 0 12 17 ] [ 0 8 13 18 ] [ 4 9 14 19 ] [ 5 10 15 20 ]

---------------------------------------------------------------------- matrix A.skewu(double k)----------------------------------------------------------------------upper-triangular with respect to the skew-diagonal

#> A = (1:20)._4; A = [ 1 6 11 16 ] [ 2 7 12 17 ] [ 3 8 13 18 ] [ 4 9 14 19 ] [ 5 10 15 20 ]

#> A.skewu(0); ans = [ 1 6 11 16 ] [ 2 7 12 0 ] [ 3 8 0 0 ] [ 4 0 0 0 ] [ 0 0 0 0 ]

---------------------------------------------------------------------- matrix p.solve----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

Returns roots of a polynomial in a matrix form

#> p = .[ 1,2,3,4,5 ] ; p = poly( 5 4 3 2 1 )

163

Page 164: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

= x^4 +2x^3 +3x^2 +4x +5

#> p.solve; ans =

[ -1.28782 - i 0.857897 ] [ -1.28782 + i 0.857897 ] [ 0.287815 - i 1.41609 ] [ 0.287815 + i 1.41609 ]

---------------------------------------------------------------------- matrix A.solve matrix A.axb----------------------------------------------------------------------nx(n+1) matrix solve Ax = b with (A|b)

#> A = [ 1,-2,-5,6; 3,-7,0,2; -5,3,-4,-8 ]; A = [ 1 -2 -5 6 ] [ 3 -7 0 2 ] [ -5 3 -4 -8 ]

#> A.solve; // A.gausspivot.backsub; ans = [ 3 ] [ 1 ] [ -1 ]

---------------------------------------------------------------------- matrix (double a, double b) .span (double n, double g=1)----------------------------------------------------------------------(a,b) .span(n,g=1) // [ x_1 = a, x_2, …, x_n = b ], dx_i = g dx_(i-1)

%> (a,b) .span(n,g=1) has a matrix of dimension 1 x n ---------------#> (0,15) .span(6) ; // g = 1 (by default) for uniform spanans = [ 0 3 6 9 12 15 ]

#> X = (0,15) .span(5,2) ; // g = 2 for increasing, dX = [ 1 2 4 8 ]X = [ 0 1 3 7 15 ]

#> X = (0,15) .span(5,0.5) ; // g = 0.5 for decreasing, dX = [ 8 4 2 1 ]X = [ 0 8 12 14 15 ]

// g = -2 for symmetric increasing, dX = [ 1 2 4 4 2 1 ]#> X = (1,15) .span(7,-2) ; X = [ 1 2 4 8 12 14 15 ]

164

Page 165: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

// g = -0.5 for symmetric decreasing, dX = [ 4 2 1 2 4 ]#> X = (1,14) .span(6,-0.5) ; X = [ 1 5 7 8 10 14 ]

---------------------------------------------------------------------- vertex v.sph ----------------------------------------------------------------------read in spherical coordinate

#> < 1,1,1 > .sph ; // R = sqrt(x^2+y^2+z^2) ans = < 1.732 0.9553 0.7854 >

---------------------------------------------------------------------- csys csys.sph ----------------------------------------------------------------------a spherical coordinate system

#> cs1 = csys.sph ; cs1 = 'sph' local csys org = < 0 0 0 > dir = [ 1 0 0 ] [ 0 1 0 ] [ 0 0 1 ]

---------------------------------------------------------------------- matrix A.spl(double x) matrix A.spl(matrix B) matrix A.spldiff matrix A.splint figure A.splplot ----------------------------------------------------------------------A.spl(x) evaluation for doubleA.spl(B) evaluation for matrixdifferentiate piecewise polynomialsintegrate piecewise polynomialsplot piecewise polynomials

Piecewise continuous polynomials are defined with a number of polynomials and corresponding intervals

165

Page 166: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

A=[ x11 x12 a10 a11 ⋯x21 x22 a20 a21 ⋯⋮ ⋮ ⋮ ⋮ ⋮xm1 xm2 am 0 am1 ⋯ ]

x11≤x ≤x12 : p1 ( x )=a10+a11 x+a12 x2+…+a1n x

n+…x21≤ x≤ x22 : p2 ( x )=a20+a21 x+a22 x

2+…+a2n xn+…

xm1≤ x≤ xm2: pm ( x )=am0+am1 x+am2 x2+…+amn x

n+…

Combination of these piecewise polynomials can be expressed by the following matrix

A=[ x11 x12 a10 a11 ⋯x21 x22 a20 a21 ⋯⋮ ⋮ ⋮ ⋮ ⋮xm1 xm2 am 0 am1 ⋯ ]

This special representation by a matrix can be handled in various ways

A.spl(x) // evaluation for double A.spl(B) // evaluation for matrix A.spldiff // differentiate piecewise polynomials A.splint // integrate piecewise polynomials A.splplot ; // plot piecewise polynomials

#> x = (0:9).tr; #> [ x, x+1, x+1 ].splplot; // spline plot

166

Page 167: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

Data set {( x1 , y1) , (x2 , y2 ) ,…, (xn, yn )} can be connected by lines and represented by piecewise continuous polynomials as follows.

#> x = [ 1, 2, 4, 5 ];; #> y = [ 3, 5, 4, 7 ];; #> P = .spline1(x,y); // spline1 for the 1st-order splines P = [ 1 2 1 2 ] [ 2 4 6 -0.5 ] [ 4 5 -8 3 ]

1≤x ≤2 : p1 ( x )=1+2 x2≤x ≤4 : p2 (x )=6−0.5x4 ≤x ≤5 : p3 ( x )=−8+3 x

#> P.splplot; // plot piecewise polynomials

#> P.spl(2.5); // p2(2.5) = 6 - 0.5(2.5) ans = 4.75

#> P.spl( [ 2.5, 3, 4.5 ] ); // evaluation by matrix ans = [ 4.75 4.5 5.5 ]

#> Q = P.splint; Q = [ 1 2 -2 1 1 ] [ 2 4 -7 6 -0.25 ] [ 4 5 21 -8 1.5 ]

1≤x ≤2 :q1 ( x )=∫1

x

p1 (z ) dz=¿∫1

x

1+2 z dz=¿−2+x+x2 ¿¿

167

Page 168: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

2≤x ≤4 :q2 ( x )=∫2

x

p2 ( z )dz+q1 (2 )=−7+6 x− 14x2

4 ≤x ≤5 :q3 ( x )=∫4

x

p3 ( z )dz+q2 (4 )=21−8x+ 32x2

#> Q.spl(4.5) - Q.spl(2.5); ans = 8.9375

∫2.5

4

p2 (x )dx+∫4

4.5

p3 ( x )dx=[−7+6x−14x2]

2.5

4

+[21−8 x+32x2]

4

4.5

=8.9375

For spline interpolation using 3rd-degree polynomials, example is

#> x = [ 1, 2, 4, 5 ];; #> y = [ 3, 5, 4, 7 ];; #> P = .spline(x,y); // 1st and 2nd columns for interval P = [ 1 2 1 0.625 2.0625 -0.6875 ] [ 2 4 -10.5 17.875 -6.5625 0.75 ] [ 4 5 89.5 -57.125 12.1875 -0.8125 ]

1≤x ≤2 : p1 ( x )=1+0.625 x+2.0625 x2−0.6875 x3

2≤x ≤4 : p2 (x )=−10.5+17.875 x−6.5625 x2+0.75 x3

4 ≤x ≤5 : p3 ( x )=89.5−57.125 x+12.1875 x2−0.8125 x3

#> P.splplot; // .spline(x,y).splplot;#> [ x', y' ].plot+ ;

#> P.splint.spl(4.5) - P.splint.spl(2.5) ; ans = 8.5068359

168

Page 169: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

∫2.5

4

p2 (x )dx+∫4

4.5

p3 ( x )dx

¿∫2.5

4

−10.5+17.875 x−6.5625 x2+0.75x3dx

+∫4

4.5

89.5−57.125 x+12.1875 x2−0.8125 x3dx

¿8.5068359

#> P.splint.splplot; // .spline(x,y) .splint .splplot; integrate

#> P.spldiff.splplot; // .spline(x,y) .spldiff .splplot; differentiate

---------------------------------------------------------------------- matrix A.spline (matrix x, matrix y) matrix A.spline1(matrix x, matrix y) matrix A.splinebc1(matrix x, matrix y) matrix A.splinebc2(matrix x, matrix y) ----------------------------------------------------------------------Piecewise continuous polynomials are defined with a number of polynomials and corresponding intervals

#> x = [ 1, 2, 4, 5 ];; #> y = [ 3, 5, 4, 7 ];;

#> P = .spline1(x,y); // spline1 for the 1st-order splines P =

169

Page 170: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 1 2 1 2 ] [ 2 4 6 -0.5 ] [ 4 5 -8 3 ]

1≤x ≤2 : p1 ( x )=1+2 x2≤x ≤4 : p2 (x )=6−0.5x4 ≤x ≤5 : p3 ( x )=−8+3 x

#> P = .spline(x,y); // 1st and 2nd columns for interval P = [ 1 2 1 0.625 2.0625 -0.6875 ] [ 2 4 -10.5 17.875 -6.5625 0.75 ] [ 4 5 89.5 -57.125 12.1875 -0.8125 ]

1≤x ≤2 : p1 ( x )=1+0.625 x+2.0625 x2−0.6875 x3

2≤x ≤4 : p2 (x )=−10.5+17.875 x−6.5625 x2+0.75 x3

4 ≤x ≤5 : p3 ( x )=89.5−57.125 x+12.1875 x2−0.8125 x3

#> P = .splinebc1(x,y); P = [ 1 2 1 0.911111 1.63333 -0.544444 ] [ 2 4 -7.06667 14.1 -5.23333 0.6 ] [ 4 5 70.6667 -45.5111 9.83333 -0.655556 ]

#> P = .splinebc2(x,y); P = [ 1 2 1 1.11111 1.33333 -0.444444 ] [ 2 4 -4.66667 11.5 -4.33333 0.5 ] [ 4 5 58.6667 -38.1111 8.33333 -0.555556 ]

----------------------------------------------------------------------Square Root Function double sqrt (double x) complex sqrt (complex z) matrix sqrt (matrix A) ----------------------------------------------------------------------#> sqrt( 4 ); ans = 2

#> sqrt( 1i ); ans = 0.707107 + 0.707107!

#> sqrt( [ 4, 1i ] ); ans = [ 2 0.707107 + i 0.707107 ]

170

Page 171: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- matrix sqrtm (matrix A) ----------------------------------------------------------------------

XX=A , X=√A

#> A = [ 1,0.3; 0.2,1 ]; sqrt(A); X = sqrtm(A); A = [ 1 0.3 ] [ 0.2 1 ] ans = [ 1 0.547723 ] [ 0.447214 1 ] X = [ 0.992355 0.151156 ] [ 0.10077 0.992355 ]

#> X^2 ; ans = [ 1 0.3 ] [ 0.2 1 ]

----------------------------------------------------------------------Triangle solutions matrix A.sss matrix A.sas matrix A.asa matrix A.ssso matrix A.saso matrix A.asao----------------------------------------------------------------------lowercase a, b, c for the sidesuppercase A, B, C for the angles S = Area, rI = radius of incircle, rO = radius of circumcircle

[ a, b, c ] .sss // two sides and in-between angle[ b, C, A ] .asa // one side and two end-angles[ a, b, C ] .sas // two sides and in-between angle

[ a, b, c ] .ssso [ a, b, C ] .saso [ b, C, A ] .asao

#> [ 3, 4, 5 ].sss;(a,b,c) = (3, 4, 5);(A,B,C) = (36.8699, 53.1301, 90);(S,rI,rO) = (6, 1, 2.5);

171

Page 172: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

ans = [ 3 4 5 ] [ 36.8699 53.1301 90 ] [ 6 1 2.5 ]

#> plot.asa(2,60,30);

---------------------------------------------------------------------- matrix A.stat ----------------------------------------------------------------------basic statistics

#> A = [ 1,2; 4,3; 2,7 ]; A = [ 1 2 ] [ 4 3 ] [ 2 7 ]

#> A.stat; 6 // entry ncount 3.16667 // mean value 19 // sum 1 // minimum 7 // maximum 1.95078 // standard deviation ans = [ 6 ] [ 3.16667 ] [ 19 ] [ 1 ] [ 7 ] [ 1.95078 ]

---------------------------------------------------------------------- matrix A.std // column-first operation----------------------------------------------------------------------standard deviation

172

Page 173: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A = [ 1,2; 4,3; 2,7 ]; A = [ 1 2 ] [ 4 3 ] [ 2 7 ]

#> A.std; ans = [ 1.52753 2.64575 ]

#> A().std; ans = [ 2.13698 ]

---------------------------------------------------------------------- matrix (double a, double b) .step (double h)----------------------------------------------------------------------(a,b) .step(h) // [ a, a+h, a+2h, ... ]a : h : b

#> 1 : 5 ;ans = [ 1 2 3 4 5 ]

#> 5 : 1 ;ans = [ 5 4 3 2 1 ]

#> 1 : 0.2: 2 ; // equivalent to (1,2).step(0.2);ans =[ 1 1.2 1.4 1.6 1.8 2 ]

---------------------------------------------------------------------- matrix W.sub(rows)(columns) // equivalent to W..(rows)(columns)----------------------------------------------------------------------Submatrix%> A ..(rows)(columns) // rows and columns are double, matrix or mixed.#> x = 1:6 ;;#> A = [ x+10; x+20; x+30; x+40; x+50; x+60 ];A =[ 11 12 13 14 15 16 ][ 21 22 23 24 25 26 ][ 31 32 33 34 35 36 ][ 41 42 43 44 45 46 ][ 51 52 53 54 55 56 ][ 61 62 63 64 65 66 ]

#> A ..( 2,1, [4,3], 6 )( 2, [5,4], 1 ); // A .sub (rows)(columns)ans =[ 22 25 24 21 ]

173

Page 174: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 12 15 14 11 ][ 42 45 44 41 ][ 32 35 34 31 ][ 62 65 64 61 ]

#> A ..( 3, [5] )(); // A .sub (rows)()ans =[ 31 32 33 34 35 36 ][ 51 52 53 54 55 56 ]

#> A ..( 2,1, [4,3], 6 )( 2, [5,4], 1 ) += (1:50)*100; // note the orderA =[ 1711 212 13 1214 715 16 ][ 1621 122 23 1124 625 26 ][ 1931 432 33 1434 935 36 ][ 1841 342 43 1344 845 46 ][ 51 52 53 54 55 56 ][ 2061 562 63 1564 1065 66 ]

#> A = .zeros(5);;#> A..(1,2)(1,2) += .ones(2); // connecting one pointA =[ 1 1 0 0 0 ][ 1 1 0 0 0 ][ 0 0 0 0 0 ][ 0 0 0 0 0 ][ 0 0 0 0 0 ]

#> A..(2,3)(2,3) += 3*.ones(2);A =[ 1 1 0 0 0 ][ 1 4 3 0 0 ][ 0 3 3 0 0 ][ 0 0 0 0 0 ][ 0 0 0 0 0 ]

#> A..(3,5)(3,5) += 7*.ones(2);A =[ 1 1 0 0 0 ][ 1 4 3 0 0 ][ 0 3 10 0 7 ][ 0 0 0 0 0 ][ 0 0 7 0 7 ]

---------------------------------------------------------------------- matrix A.subdel(rows)(columns)

174

Page 175: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------delete submatrix

#> X = [ 11:14; 21:24; 31:34; 41:44; 51:54 ];X = [ 11 12 13 14 ] [ 21 22 23 24 ] [ 31 32 33 34 ] [ 41 42 43 44 ] [ 51 52 53 54 ]

#> A.subdel(1,2,5)(); ans = [ 31 32 33 34 ] [ 41 42 43 44 ]

#> A.subdel()(2,4); ans = [ 11 13 ] [ 21 23 ] [ 31 33 ] [ 41 43 ] [ 51 53 ]

// equivalent to A = A.subdel(1,2,5)(2,4);#> A = X;; A..(1,2,5)(2,4) = [];A = [ 31 33 ] [ 41 43 ]

---------------------------------------------------------------------- matrix A.sum // column-first operation double A.sum1 // equivalent to A.sum.sum(1) ----------------------------------------------------------------------sum of elements

#> A = [ 1,2; 4,3; 2,7 ]; A = [ 1 2 ] [ 4 3 ] [ 2 7 ]

#> A.sum; ans = [ 7 12 ]

#> A().sum;

175

Page 176: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

ans = [ 19 ]

#> A.sum1; ans = 19

---------------------------------------------------------------------- double p.sum----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .∑ ¿a0+a1+a2+a3+…+an

#> p = .[ 1,2,3,4,5 ] ; p = poly( 5 4 3 2 1 )

= x^4 +2x^3 +3x^2 +4x +5

#> p .sum ; // sum of all coefficients ans = 15----------------------------------------------------------------------dot-only Function void .swap (double &x, double &y) dot-only void .swap (complex &x, complex &y) void .swap (matrix &x, matrix &y) void .swap (poly &x, poly &y) void .swap (vertex &x, vertex &y) ----------------------------------------------------------------------swap two arguments

#> a = 2; b = 3; .swap(a,b); a; b;

a = 2 b = 3 a = 3 b = 2

#> z = 2i; w = 3i; .swap(z,w); z; w;

z = 0 + 2! w = 0 + 3! z = 0 + 3! w = 0 + 2!

#> p = .[1,2]; q = .[3,4]; .swap(p,q); p ; q;

p = poly( 2 1 ) = x +2 q = poly( 4 3 ) = 3x +4 p = poly( 4 3 )

176

Page 177: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

= 3x +4 q = poly( 2 1 ) = x +2

#> A = [1,2]; B = [3,4]; .swap(A,B); A ; B;

A = [ 1 2 ] B = [ 3 4 ] A = [ 3 4 ] B = [ 1 2 ]

#> u = < 1,2 >; v = < 3,4 >; .swap(u,v); u; v;

u = < 1 2 0 > v = < 3 4 0 > u = < 3 4 0 > v = < 1 2 0 >

---------------------------------------------------------------------- matrix A.swap (double i, double j) matrix A.rowswap(double i, double j) ----------------------------------------------------------------------elementary row operation, swap rows

A=[ Ri

⋯R j

] where Rk is k -th row. A.swai(i,j) = [R j

⋯R i

] #> A = [ 2,1,4 ; -1,3,5 ]; A = [ 2 1 4 ] [ -1 3 5 ]

#> A.swap(1,2); ans = [ -1 3 5 ] [ 2 1 4 ]

---------------------------------------------------------------------- poly p.syndiv(double c) matrix p.syndiv(poly q) ----------------------------------------------------------------------p %% q , synthetic division by polynomial q

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

First Description (1): p.syndiv(c) is equal to p %% c

177

Page 178: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

A syntheticdivisionby a factor (x−c) is defined as

p ( x )=a0+a1 x+a2x2+a3 x

3+…+an xn

p ( x )=p (x )¿b0+b1 ( x−c )+b2 (x−c )2+b3 (x−c )3+…+bn ( x−c )n

the coefficients are determined by comparing two expressions such that

p ( x )=a0+a1 x+a2 x2+…+an x

n

¿b0+b1(x−c )+b2(x−c)2+…+bn(x−c )n

An example isx3+4 x2+3 x+2=( x+3 )3−5 ( x+3 )2+6 ( x+3 )+2

%> synthetic division by a factor x-c#> p = .[1,4,3,2]; p = poly( 2 3 4 1 ) = x^3 +4x^2 +3x +2

#> p.syndiv(-3) ; // equivalent to p %% -3; ans = poly( 2 6 -5 1 ) = x^3 -5x^2 +6x +2

#> ans ( .[1,3] ); // ans = p %% -3 ; from the above command ans = poly( 2 3 4 1 ) = x^3 +4x^2 +3x +2

Second Description (2): p.syndiv(q) is equal to p %% q

The synthetic division by higher degrees can be also treated by an operator ‘%%’. For example

x5+8 x4+6 x3+3 x2−10 x+2(x2+x+1 )2

= −6 x+4(x2+ x+1 )2 +

−9 x−8(x2+x+1 )

+(x+6)

This has a nature similar to synthetic division

178

Page 179: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

x5+8 x4+6 x3+3 x2−10 x+2¿ ( x+6 ) (x2+x+1 )2+(−9x−8 ) ( x2+x+1 )+(−6 x+4)

An operator ‘%%’ for this case can be applied

%> synthetic division by a polynomial

#> p = .[ 1,8,6,3,-10,2 ]; p = poly( 2 -10 3 6 8 1 ) = x^5 +8x^4 +6x^3 +3x^2 -10x +2

#> q = .[1,1,1]; // equal to q = poly(1,1,1); q = poly( 1 1 1 ) = x^2 +x +1

#> A = p %% q ; // ascending poly A = [ 4 -6 ] [ -8 -9 ] [ 6 1 ]

#> -p + A.row(1).apoly+ A.row(2).apoly*q + A.row(3).apoly*q^2; ans = poly( 0 ) = 0

x5+8 x4+6 x3+3 x2−10 x+2¿ (4−6x )+ (−8−9 x ) ( x2+x+1 )+(6+x ) (x2+ x+1 )2

The final command confirms that the partial fraction is correct. Note that a matrix is returned by p instead of polynomial array.

[ T ]

---------------------------------------------------------------------- double .T_n(double x) dot-only matrix .T_n(matrix x), for real-part only----------------------------------------------------------------------Tchebyshev polynomial of degree n

179

Page 180: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

T 0 ( x )=1 , T 1 ( x )=x ,T n (x )=2x Tn−1 ( x )−T n−2(x )

#> .T_5(0.3); ans = 0.99888

#> .T_5( [0.3,0.4] ); ans = [ 0.99888 0.88384 ]

#> .hold; for.n(1,5) plot.x(-1,1) ( .T_n(x) ); plot;

---------------------------------------------------------------------- poly poly.T(double n) ----------------------------------------------------------------------Tchebyshev polynomial of degree n

T 0 ( x )=1 , T 1 ( x )=x ,T n (x )=2x Tn−1 ( x )−T n−2(x )

This command is for finding a polynomial itself. For evaluation, it is more convenient to use

.T_n(x)

#> for.n(0,5) poly.T(n); ans = poly( 1 )

= 1 ans = poly( 0 1 ) = x ans = poly( -1 0 2 ) = 2x^2 -1 ans = poly( -0 -3 0 4 ) = 4x^3 -3x ans = poly( 1 -0 -8 0 8 ) = 8x^4 -8x^2 +1 ans = poly( 0 5 -0 -20 0 16 ) = 16x^5 -20x^3 +5x

#> .hold; for.n(0,5) plot.x(-1,1) ( .T_n(x) ); plot;

180

Page 181: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

----------------------------------------------------------------------Tangent Function double tan(double x) complex tan(complex z) matrix tan(matrix A)----------------------------------------------------------------------

tan ( x+π )=tan ( x )−π2

<x< π2,−∞< tan ( x )<∞

#> tan( pi/4 ); ans = 1

#> tan( 2i ); ans = 0 + 0.964028!

#> tan( [ pi/4, 2i ] ); ans = [ 1 0 + i 0.964028 ]

#> plot.x( -pi/2+0.1,pi/2-0.1 ) ( tan(x) );

----------------------------------------------------------------------Tangent Function in Degree double tand(double x) complex tand(complex z) matrix tand(matrix A)----------------------------------------------------------------------

181

Page 182: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

tand ( x )=tan( πx180 ) ,tand ( x+180 )=tand (x)

−90<x<90−∞<tand ( x )<∞

#> tand( 45 ); ans = 1

#> tand( 2.todeg! ); ans = 0 + 0.964028!

#> tand( [ 45, 2.todeg! ] ); ans = [ 1 0 + i 0.964028 ]

#> plot.x( -85,85 ) ( tand(x) );

----------------------------------------------------------------------Hyperbolic Tangent Function double tanh(double x) complex tanh(complex z) matrix tanh(matrix A)----------------------------------------------------------------------

tanh ( x )= ex−e− x

ex+e− x2−∞<x<∞ ,−1< tanh ( x )<1

#> tanh( pi ); ans = 0.99627208

#> tanh( 2i ); ans = 0 - 2.18504!

#> tanh( [ pi, 2i ] ); ans = [ 0.996272 0 - i 2.18504 ]

182

Page 183: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> plot.x( -5,5 ) ( tanh(x) );

---------------------------------------------------------------------- poly p.tay ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .tay=a0+a1 x+a2 x2 / 2 !+a3 x

3 / 3 !+…+an xn / n !

#> p = .[ 1,2,3,4,5 ] ; p = poly( 5 4 3 2 1 )

= x^4 +2x^3 +3x^2 +4x +5

#> p .tay ; ans = poly( 5 4 1.5 0.333333 0.0416667 )

= 0.0416667x^4 +0.333333x^3 +1.5x^2 +4x +5

#> p .tay.iratio ; ans = poly( 5 4 3/2 1/3 1/24 )

---------------------------------------------------------------------- matrix .tdma(matrix a,matrix b,matrix c,matrix d, double na,nb) dot-only----------------------------------------------------------------------tridiagonal matrix algorithm

(Tri-Diagonal Matrix Algorithm)a i x i+bi xi−1+c i x i+1=d i ,i=1,2,3 ,⋯ , n ,b1=cn=0

183

Page 184: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

P1=−c1

a1,Q1=

d1

a1

Pi=−c i

ai+b iPi−1,Qi=

d i−b iQi−1

ai+b iPi−1, i=2,3,4 ,⋯ , n

xn=Qn

x i=Pi x i+1+Q i , i=n−1 ,n−2 ,⋯ ,3,2,1

//----------------------------------------------------------------------// tridiagonal matrix algorithm (TDMA)// a(i)*x(i) + b(i)*x(i-1) + c(i)*x(i+1) = d(i), b(1) = c(n) = 0//----------------------------------------------------------------------matrix user_tdma(a,b,c,d, double na,nb) { n = a.mn; P = Q = x = .zeros(1,n); P(na) = -c(na)/a(na); Q(na) = d(na)/a(na); for.i(na+1,nb) { // for(i = na+1; i <= nb; i++) den = 1/( a(i) + b(i)*P(i-1) + _eps ); P(i) = -c(i) * den; Q(i) = (d(i) - b(i) * Q(i-1))*den; } x(nb) = Q(nb); for.i(nb-1,na,-1) x(i) = P(i)*x(i+1)+Q(i); // for(i = nb-1; i >= na; i--) return x;}

// An example is shown below#> n = 6;#> a = b = c = d = .zeros(1,n);; // create matrices #> a = 2;#> b = 1;#> c = 1;#> for.i(1,n) d(i) = i;;#> x = .tdma(a,b,c,d, 1,n).trun12; n = 6 a = [ 2 2 2 2 2 2 ] b = [ 1 1 1 1 1 1 ] c = [ 1 1 1 1 1 1 ] ans = [ 0 1 0 2 0 3 ]

---------------------------------------------------------------------- double x.todeg ----------------------------------------------------------------------x * 180 / pi, radian to degree

184

Page 185: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> pi.todeg; ans = 180

---------------------------------------------------------------------- matrix matrix.toep (matrix A, matrix B) ----------------------------------------------------------------------#> matrix.toep ([1,0,-1,-2],[1,2,4,8]); // toeplitzans = [ 1 2 4 8 ] [ 0 1 2 4 ] [ -1 0 1 2 ] [ -2 -1 0 1 ]

---------------------------------------------------------------------- double x.torad ----------------------------------------------------------------------x * pi / 180, degree to radian

#> 180.torad; ans = 3.1415927

---------------------------------------------------------------------- matrix A.tr equivalent to A.' = A.tr----------------------------------------------------------------------transpose, [ AT ]i , j=[A ] j ,i

A=[a1 a4 a7 a10

a2 a5 a8 a11

a3 a6 a9 a12] A .'=A . tr=[ a1 a2 a3

a4 a5 a6

a7 a8 a9

a10 a11 a12]

#> A = [ 1+1i, 2-3i; 5-4i, 3+1i; 2+3i, -1+5i ]; A = [ 1 + i 1 2 - i 3 ] [ 5 - i 4 3 + i 1 ] [ 2 + i 3 -1 + i 5 ]

#> A.'; // A.' = A.tr ans = [ 1 - i 1 5 + i 4 2 - i 3 ] [ 2 + i 3 3 - i 1 -1 - i 5 ]

#> A'; // compare with A' = A.conjtr ans =

185

Page 186: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 1 - i 1 5 + i 4 2 - i 3 ] [ 2 + i 3 3 - i 1 -1 - i 5 ]

---------------------------------------------------------------------- double A.trace ----------------------------------------------------------------------

∑i=0

n

aii#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.trace; ans = 15

---------------------------------------------------------------------- double trapz(matrix x,matrix y) ----------------------------------------------------------------------area by the trapezodial rule

12¿

⋯+(xn−xn−1 ) ( yn−1+ yn )¿

#> x = 0:0.01:1;; y=1 ./(1+x.^2);; trapz(x,y); ans = 0.785394

#> int.x(0,1) ( 1/(1+x^2) ); pi/4; ans = 0.78539816 ans = 0.78539816

---------------------------------------------------------------------- matrix A.tril(double k) ----------------------------------------------------------------------lower-triangular

A=[a11 a12 a13 a14

a21 a22 a23 a24

a31 a32 a33 a34] , A .tril(0)=[ a11 0 0 0

a21 a22 0 0a31 a32 a33 0]

#> A = (1:12)._4; A = [ 1 4 7 10 ]

186

Page 187: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.tril(0); ans = [ 1 0 0 0 ] [ 2 5 0 0 ] [ 3 6 9 0 ]

#> A.tril(-1); ans = [ 0 0 0 0 ] [ 2 0 0 0 ] [ 3 6 0 0 ]

---------------------------------------------------------------------- matrix A.triu(double k)----------------------------------------------------------------------upper-triangular

A=[a11 a12 a13 a14

a21 a22 a23 a24

a31 a32 a33 a34] , A .triu (0 )=[a11 a12 a13 a14

0 a22 a23 a24

0 0 a33 a34]

#> A = (1:12)._4; A = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 3 6 9 12 ]

#> A.triu(0); ans = [ 1 4 7 10 ] [ 0 5 8 11 ] [ 0 0 9 12 ]

#> A.triu(-1); ans = [ 1 4 7 10 ] [ 2 5 8 11 ] [ 0 6 9 12 ]

---------------------------------------------------------------------- matrix A.true matrix A.find----------------------------------------------------------------------index for nonzero elements

187

Page 188: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> A = [ 2,0,3; 0,-1,0; 0,2,4 ]; A = [ 2 0 3 ] [ 0 -1 0 ] [ 0 2 4 ]

#> A.true; ans = [ 1 5 6 7 9 ]

#> A.false; ans = [ 2 3 4 8 ]

---------------------------------------------------------------------- double x.trun(eps=1.e-30) matrix A.trun(eps=1.e-30) poly p.trun(eps=1.e-30) vertex v.trun(eps=1.e-30) double x.trunk ϵ=10−k matrix A.trunk ϵ=10−k poly p.trunk ϵ=10−k vertex v.trunk ϵ=10−k ----------------------------------------------------------------------truncate x, i.e. make x=0 if ¿ x |<ϵ

only a sample case of a matrix is considered below. All other types can be done in an element-by-element manner.

#> [ 0.001, 2.e-10, 3.e-13, 5.e-17 ].trun; ans = [ 0.001 2e-010 3e-013 5e-017 ]

#> [ 0.001, 2.e-10, 3.e-13, 5.e-17 ].trun2; ans = [ 0 0 0 0 ]

#> [ 0.001, 2.e-10, 3.e-13, 5.e-17 ].trun10; ans = [ 0.001 2e-010 0 0 ]

#> [ 0.001, 2.e-10, 3.e-13, 5.e-17 ].trun16; ans = [ 0.001 2e-010 3e-013 0 ]

[ U ]

---------------------------------------------------------------------- matrix A.unit

188

Page 189: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

matrix A.colunit----------------------------------------------------------------------makes k -th column to be a1k

2 +a2 k2 +a3k

2 +…+amk2 =1 , xT x=1

#> A = [ 1,2,3,4; 5,6,4,8 ]; A = [ 1 2 3 4 ] [ 5 6 4 8 ]

#> A.unit; // the same as A.colunit ans = [ 0.196116 0.316228 0.6 0.447214 ] [ 0.980581 0.948683 0.8 0.894427 ]

---------------------------------------------------------------------- complex z.unit ----------------------------------------------------------------------normalize a complex number

#> z = 3+4! ; z = 3 + 4!

#> z.unit ; ans = 0.6 + 0.8!

---------------------------------------------------------------------- vertex v.unit ----------------------------------------------------------------------normalize a vertex

#> v = < 1,1,1 >; v = < 1 1 1 >

#> v.unit; ans = < 0.5774 0.5774 0.5774 >

---------------------------------------------------------------------- poly p.up(double k) ----------------------------------------------------------------------

p ( x )=a0+a1 x+a2 x2+a3 x

3+…+an xn

p .up ( k )=a0 xk+a1 x

1+k+a2 x2+k+…+an x

n+k

#> p = .[ 1,2,3,4,5 ]; p = poly( 5 4 3 2 1 ) = x^4 +2x^3 +3x^2 +4x +5

189

Page 190: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

#> p .up(3) ; // replace x by x^3ans = poly( 0 0 0 5 4 3 2 1 )

= x^7 +2x^6 +3x^5 +4x^4 +5x^3

[ V ]

---------------------------------------------------------------------- matrix A.vander(double nrow) ----------------------------------------------------------------------Vandermonde matrix

[1 1 1x1 x2 x3

⋯ 1 1∙ xn−1 xn

∙ ∙∙ ∙x1r x2

r

∙ ∙∙ ∙x3r ∙

∙ ∙∙ ∙

xn−1r xn

r ]#> x = [ 1,2,3,4 ]; x = [ 1 2 3 4 ]

#> x.vander(3); ans = [ 1 1 1 1 ] [ 1 2 3 4 ] [ 1 4 9 16 ]

---------------------------------------------------------------------- matrix A.var // column-first operation----------------------------------------------------------------------variance

#> A = [ 1,2; 4,3; 2,7 ]; A = [ 1 2 ] [ 4 3 ] [ 2 7 ]

#> A.var; ans = [ 2.33333 7 ]

#> A().var; ans = [ 4.56667 ]

190

Page 191: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

---------------------------------------------------------------------- matrix .vertcat( ...) ----------------------------------------------------------------------vertical concatenation

#> .vertcat( 1,2,[3,4,5], 6,[ -1,-2] ); ans = [ 1 0 0 ] [ 2 0 0 ] [ 3 4 5 ] [ 6 6 6 ] [ -1 -2 0 ]

[ W ]

---------------------------------------------------------------------- matrix A.wide(double n) // equivalent to A..n = A.wide(n)----------------------------------------------------------------------reshape in n-column

#> A = (1:20)._3; A = [ 1 8 15 ] [ 2 9 16 ] [ 3 10 17 ] [ 4 11 18 ] [ 5 12 19 ] [ 6 13 20 ] [ 7 14 0 ]

#> A .wide(4); ans = [ 1 7 13 19 ] [ 2 8 14 20 ] [ 3 9 15 0 ] [ 4 10 16 0 ] [ 5 11 17 0 ] [ 6 12 18 0 ]

---------------------------------------------------------------------- void A.write(string fmt) ----------------------------------------------------------------------write A to a file

191

Page 192: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

[ X ]

---------------------------------------------------------------------- double z.x // both read/write double z.y ----------------------------------------------------------------------z.x real part of a complex numberz.y imaginary part of a complex number

#> z = 3+4!; z = 3 + 4!

#> z.x = 21; z;ans = 21z = 21 + 4!

#> z.y = 39; z;ans = 39z = 21 + 39!

---------------------------------------------------------------------- double v.x // both read/write double v.y double v.z ----------------------------------------------------------------------%> rectangular coordinate ----------------------------------------------#> v = < 1,1,1 > ; v.x; v.y; v.z; v = < 1 1 1 >

#> v.x; v.y; v.z; ans = 1 ans = 1 ans = 1

#> v.x += 1 ; // only x is changed v = < 2 1 1 >

---------------------------------------------------------------------- matrix A.xrot(double theta) matrix A.yrot(double theta) matrix A.zrot(double theta)

matrix A.xrotd(double theta) in degree

192

Page 193: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

matrix A.yrotd(double theta) matrix A.zrotd(double theta)------------------------------- ---------------------------------------tensor-related functions for stress analysisrotation around the x-axisrotation around the y-axisrotation around the z-axis

σ=[ i j k ] [σ11 σ12 σ13

σ21 σ22 σ23

σ31 σ32 σ33][ ijk ] ,[ ijk ]=Q [e1

e2

e3]

σ=[e1 e2 e3 ]QT [σ11 σ 12 σ13

σ21 σ 22 σ23

σ31 σ 32 σ33]Q [e1

e2

e3]

~S=QT [ σ11 σ12 σ 13

σ 21 σ22 σ 23

σ 31 σ32 σ 33]Q

// s = ( ij+ji ), pure shear stress#> X = [ 0,1,0; 1,0,0; 0,0,0 ]; X =[ 0 1 0 ][ 1 0 0 ][ 0 0 0 ]

// snew = ( uu-vv ), tension and compression#> X.zrotd(45).trun10; ans =[ 1 0 0 ][ 0 -1 0 ][ 0 0 0 ]

---------------------------------------------------------------------- vertex v.xrot(double theta) vertex v.yrot(double theta) vertex v zrot(double theta)

vertex v.xrotd(double theta) in degree

193

Page 194: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

vertex v.yrotd(double theta) vertex v.zrotd(double theta)------------------------------- ---------------------------------------rotation around the x-axisrotation around the y-axisrotation around the z-axis

#> v = < 1,1,1 > ; v.zrotd(45).trun10; v = < 1 1 1 > ans = < 0 1.414 1 >

[ Y ]

----------------------------------------------------------------------Bessel Function double .Y_(double nu)(double x) dot-only matrix .Y_(double nu)(matrix x) matrix .Y_(matrix nu)(double x) matrix .Y_(matrix nu)(matrix x) ----------------------------------------------------------------------under test

---------------------------------------------------------------------- void .ym(double year, double month) dot-only----------------------------------------------------------------------print calendar

#> .ym(2012,8);2012 8 Sun Mon Tue Wed Thr Fri Sat __ __ __ 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

[ Z ]

---------------------------------------------------------------------- matrix .zeros(double m, double n = m)----------------------------------------------------------------------

194

Page 195: Web viewThe return value of acosh is the positive inverse or the complex inverse with the smallest argument

[100] 300 Reference, Tutorial by www.msharpmath.com

all-zeros matrix

#> .zeros(2,4); ans = [ 0 0 0 0 ] [ 0 0 0 0 ]

#> .zeros(3); ans = [ 0 0 0 ] [ 0 0 0 ] [ 0 0 0 ]

---------------------------------------------------------------------- end of file----------------------------------------------------------------------

195