News

“msharpmath”, The Simple is the Best

[100] 091 News     News

Dec. 10, 2012 =======================================
m#math  2.22 is newly upgraded.
▶indefinite integrals are treated by a dot function ‘.integ(a,b,f(x))’. For example,

#> double f(x) = exp(-x*x);  .integ(-inf,inf,f);  sqrt(pi);
ans =       1.7724539
ans =       1.7724539

#> double f(x) = 1/sqrt(1-x^2);  .integ(0,1,f);  asin(1);
ans =       1.5707658
ans =       1.5707963

For discrete data, either ‘.spline(x,y).splint’, ‘trapz’ or ‘cumtrapz’ can be employed.

Nov. 26, 2012 =======================================
m#math  2.20   has a few revisions.

▶ Three different grammars for an iterative command ‘for’. The following two commands in C-language,

for(i = a; i <= b; i += c ) stmt; // if a < b and c > 0
for(i = a; i >= b; i -= c ) stmt; // if a > b and c > 0

are working in m#math as it is. Also, an alternative expression

for .i (a,b,c=1) stmt;
for[10] stmt;

works in m#math. For example,

// Pibonachi 1 1 2 3 5 8 13 21 34 55 89 144
#> (a,b)=( 1,1);;   for[10] (a,b) = (b,a+b);;    b;
b = 144

#> s = 0; for.n(1,10) s += n;  // 1+2+3+4+5+6+7+8+9+10 = 55
s = 0
s = 1
s = 3

s = 55

Note that exchanging values among variables are done by beanpods such that

#> (a,b,c) = (1,2,3); (b,c,a) = (a,b,c);
a = 1
b = 2
c = 3
b = 1
c = 2
a = 3

▶ The old command “A..B” for dot product is changed to “A**B”.
▶ A.wide(n) = A._n ; // a new operator “._” replaces old one “..”
#> (1:12)._4;
ans =
[ 1 4 7 10 ]
[ 2 5 8 11 ]
[ 3 6 9 12 ]

 

Nov. 19, 2012 =======================================

m#math 2.19  handles stiff ODE (ordinary differential equations) by Spoke ‘.stiff(tol=0.01)’ . An example is from the van der Pol equations.

#> ode.x[15000](0,300) ( y” = 100*(1-y*y)*y’ -y, y= 2,y’=0 ).stiff .plot;

Oct. 22, 2012 =======================================

In declaring a polynomial, Msharpmath V2.16 announces the most simplest method. It is just by using a leading dot !
[ list ]   is a matrix
.[ list ]  is a polynomial !!!

#> .[ 1,2,3 ];  // old version  [ 1,2,3 ].poly can be used alternatively
y = x^2 + 2x + 3
roots
[            -1 - i 1.41421        ]
[            -1 + i 1.41421        ]
vertex at ( -1, 2 )
y_minimum = 2
y-axis intersect ( 0, 3 )
symmetry at x = -1
directrix at y = 1.75
focus at ( -1, 2.25 )

#> .[1,3]*.[1,9,7]*.[1,-5,3,4] ; // (x+3)(x^2+9x+7)(x^3-5x^2+3x+4)
ans = poly( 84  199  45  -109  -23  7  1 )
= x^6 +7x^5 -23x^4 -109x^3 +45x^2
+199x +84

▶ dot-only function ‘.tdma(A,B,C,D, na,nb)’ is implemented for tridiagonal matrix algorithm.
▶ 0 x 0 matrix [] is available now.
▶ dot functions ” .horzcat”, “.vertcat”, “.diagcat” now handle multiple arguments.

.horzcat(A1,A2,A3, …)   // horizontal concatenation
.vertcat(A1,A2,A3, … )  // vertical concatenation, stack
.diagcat(A1,A2,A3,…)    // diagonal concatenation, the same as “blkdiag” in matlab

When two arguments are involved, binary operators work also

A | B       // .horzcat(A,B)
A _ B      // .vertcat(A,B)
A \_ B    //  .diagcat(A,B)
A |= B     //  A = A | B
A _= B    //  A = A _ B
A \_= B  //  A = A \_ B

Oct. 04, 2012 ===================================
A special variable ‘ans’ is implemented in Msharpmath V2.14 as in other softwares such as Matlab. All other variables are of fixed data type, but the special variable ‘ans’ can be changed each time it is defined. For example,

#> 3+4 ;
ans =               7
#> ans / 10 ;
ans =             0.7
#> [ 1,2,3 ] ;
ans =  [             1             2             3 ]
#> ans .* ans ;
ans =  [             1             4             9 ]

A few dot-only-functions are implemented

.bisect(a,b, f(x))    // to find a root of f(x)=0
.secant(a,b,f(x))     // root of f(x)=0 via the secant method
.spline(X,F)          // 3rd-order spline interpolation
.spline1(X,F)         // 1st-order spline interpolation
.polyfit(X,F, kth)    // kth-degree polynomial regression, .regress(X,F,kth)
.regress(X,F,mftn(x)) // regression curve by matrix mftn(double x)

Data set { (x_1,y_1),(x_2,y_2),…,(x_n,y_n) } can be connected by splines and represented by piecewise continuous polynomials as follows. In a spline matrix, the first two columns indicate both ends of each interval.

#> x =  [           1           2           4           5 ];;
#> f =  [           3           5           4           7 ];;
#> P = .spline(x,f);  // 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∶ p_1(x)=1 + 0.625x + 2.0625x^2 – 0.6875x^3
// 2≤x≤4∶ p_2(x)=-10.5 + 17.875x – 6.5625x^2 + 0.75x^3
// 4≤x≤5∶ p_3(x)=89.5 – 57.125x + 12.1875x^2 – 0.8125x^3

#> P.splplot;                              // .spline(x,f).splplot;
#> [ x', f' ].plot+ ;                       // given data
#> .polyfit(x,f,1).plot+(1,5);   // 1st-degree polynomial regression

#> P.spldiff.splplot;  // .spline(x,f) .spldiff .splplot;  differentiate
#> P.splint.splplot;   // .spline(x,f) .splint .splplot;  integrate

Sep. 23, 2012 ===================================

Operators for set are  available from Msharpmath V2.13. We believe that education of set concept in High-Schools can be particularly aided by these operators.

A ++ B         // set union,             [2,3,4]++[3,4,5] = [2,3,4,5]
A – - B         // set difference,      [2,3,4]- -[3,4,5] = [2]
A /\ B          // set intersection,  [2,3,4]/\[3,4,5] = [3,4]
++A             // ++A = A++A, remove duplicate elements, ++[1,2,3,1,2]=[1,2,3]
A ++= B      //   A = A ++ B
A – -= B      //   A = A – - B
A /\= B       //   A = A /\ B

Example usages are listed below.
#> matrix.format(“%3g”);
#> A = [2,3,4,3,4,6]; B = [1,2,3,2,3,8,8,9];
A =  [  2  3  4  3  4  6 ]     B =  [  1  2  3  2  3  8  8  9 ]

#> A++B;                           ans =  [  2  3  4  6  1  8  9 ]
#> A–B;  B–A;                 ans =  [  4  6 ]     ans =  [  1  8  9 ]
#> A/\B;                            ans =  [  2  3 ]
#> (0:2:30)/\(0:3:30);   ans = [ 0 6 12 18 24 30 ]

Sep. 18, 2012 ===================================

Msharpmath beta Version V2.12 is released on the homepage. In this new version, dot functions are refined to cover the Bessel functions and special polynomials.

.I_nu(x) .J_nu(x) .K_nu(x) .Y_nu(x)   // Bessel functions
.P_n(x)   // Legendre polynomial
.T_n(x)   // Tchebyshev polynomial
.H_n(x)   // Hermite polynomial
.L_n(x)   // Laguerre polynomial

#> nu = 1;;   x = 0.3;;
#> .J_nu(x);                      ans =      0.14831882
#> .I_nu+1/2(x);             ans =     0.044096517
#> .K_nu*nu(x);              ans =      0.48323019
#> .Y_nu+2/3(x);            ans =      -7.0231754
#> .J_nu( 0.3:0.1:0.6 );  ans =  [      0.148319      0.196027      0.242268      0.286701 ]

Therefore, math.J_nu(x) in old version is no more recommended.

A member function of a matrix ‘A.rowskip(k)’ is newly added.

Comments are closed.