Labels

Wednesday, October 31, 2018

Powerful string processor with c++

/*MYSTR.h*/
 #ifndef _mystr_
 #define _mystr_
 #include<string>
 #include<dirent.h>
 #include<vector>
 
 /* strim remove space from front/end of string */
 /* sreduce remove all redundancy space */
 /* sremove_spaces remove all of space in string */
 std::string strim(const std::string& str, const std::string& whitespace = " \t");
 std::string sreduce(const std::string& str,const std::string& fill = " ",const std::string& whitespace = " \t");
 std::string inline sremove_spaces(std::string str);
 std::vector lisidir(const char *path);
 #endif

Strengthen the matrix in Gun Scientific Library (GSL)

/* MYMATRIX.h */

 #include <stdio.h>
 #include <string.h>
 #include <vector>
 #include <assert.h>
 #include <gsl/gsl_linalg.h>
 #include <gsl/gsl_matrix.h>
 /* arbitrary maximum size */
 #define MAXSIZE 5000*10000 

 void print_matrix( const gsl_matrix *,const char *);
 void fprint_matrix( const char *filename, const gsl_matrix *m, const char *comment ="");
 gsl_matrix * fread_matrix( const char *filen, int *rows, int *clos, int transpose);
 gsl_matrix * vector2matrix(const std::vector<double> x,const std::vector<double>y);

Thursday, October 25, 2018

Resource tools

online math editor
https://www.mathcha.io


Harvard Fairbank Center for Chinese Studies
https://soundcloud.com/fairbank-center


Digital tools for researchers
Code Ocean is a research collaboration platform that provides researchers and developers an easy way to create, collaborate on, share, discover, and run code for private projects and to be published in academic journals and conferences.
Writefull is an app that gives feedback on your writing by checking your text against databases of correct language.


Second-Order Linear Differential Equations
https://www.stewartcalculus.com/data/CALCULUS%20Concepts%20and%20Contexts/upfiles/3c3-2ndOrderLinearEqns_Stu.pdf
http://tutorial.math.lamar.edu/Classes/DE/NonhomogeneousDE.aspx


Repl.it is a development environment that gives you an instant IDE to learn, build, collaborate, and host all on one platform.


Colaboratory is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud.
With Colaboratory you can write and execute code, save and share your analyses, and access powerful computing resources, all for free from your browser.


online pdf editor
https://online.sodapdf.com/#/home?r=view

itermplot
An awesome iTerm2 backend for Matplotlib, so you can plot directly in your terminal.

https://iris.ai/
Speed up literature review

Arxiv Sanity
Web interface for browsing, search and filtering recent arxiv submissions

tool collection
http://tools.kausalflow.com/

Fighting Internet Censorship in a Mass!


is a remote terminal application that supports intermittent connectivity, allows roaming, and provides speculative local echo and line editing of user keystrokes.

MATHS WITH PYTHON 3: DIFFUSION EQUATION

ping.pe

numerical solve differential eqn


Introduction to Scientific Python programming


Assimulo is a simulation package for solving ordinary differential equations. It is written in the high-level programming language Python and combines a variety of different solvers written in FORTRAN, C and even Python via a common high-level interface

Comparing measures of similarity between curves


http://bbs.vicl.net/forum-44-1.html

https://1lib.us/

https://delta.chat/en/  chat with mails

国际JCI认证的医院


opensource grammar check


watch movie online


GIZMO, PIERNIK, Athena++, stochastic-parker


Tuesday, October 23, 2018

Gamma emission from the interaction between cosmic rays and molecular cloud

\begin{split}
 \Phi_{\gamma} = & \frac{1}{4\pi d^2} \int dE'{ [\frac{4\pi}{c} \frac{dN}{dE'}(E')] *V} [ \frac{M_{mc}}{Vm_p}] \frac{d\sigma}{dE}(E,E')  c \\
 = & \frac{M_{mc}}{d^2m_p} \int dE' \frac{dN}{dE'}(E') \frac{d\sigma}{dE}(E,E')
\end{split}

\[ N \propto exp(-\frac{r^2}{4Dt}) \]

$E_{\gamma} \sim 10\%E_p$

Friday, October 19, 2018

Return a array from function in C language

void func1(double a[])
{
   /* code */
}


void func2(void)
{
   /*  double *t = (double *) malloc(sizeof(double)*array_length); */ //c++ 
   double *t = malloc(sizeof(double)*array_length);
   /* remember to free(t) later */
   /* code */
}


double * func3(double a[])
{
   /* code */
   return a;
}


REFERENCE:
https://stackoverflow.com/questions/3473438/return-array-in-a-function

Find the inverse of a matrix with C

This origin code is wrote by "mop" http://forums.codeguru.com/showthread.php?262248-Algorithm-for-matrix-inversion .
I made a little change.

If you use GSL library, there is a simple example to get the inverse of matrix https://lists.gnu.org/archive/html/help-gsl/2008-11/msg00001.html.

 #include<cstdlib>                                                                                                                                                                          
 #include<math.h>                                                                                                                                                                            
 #include<stdio.h>

float* MatrixInversion(float* A, int n)                                                                                                                                                      
{                                                                                                                                                                                            
// A = input matrix (n x n)                                                                                                                                                              
// n = dimension of A                                                                                                                                                                    
// AInverse = inverted matrix (n x n)                                                                                                                                                    
// This function inverts a matrix based on the Gauss Jordan method.                                                                                                                      
// The function returns 1 on success, 0 on failure.                                                                                                                                      
   int i, j, iPass, imx, icol, irow;                                                                                                                                                        
   float det, temp, pivot, factor;                                                                                                                                                          

   float* ac = (float*)calloc(n*n, sizeof(float));
   float* AInverse = (float*)calloc(n*n, sizeof(float));                                                                                                                                           
   det = 1;                                                                                                                                                                                 
                                                                                                                                                                             
   for (i = 0; i < n; i++)                                                                                                                                                                  
   {                                                                                                                                                                                        
       for (j = 0; j < n; j++)                                                                                                                                                              
       {                                                                                                                                                                                    
           //AInverse[0] = 0;                                                                                                                                                               
           AInverse[n*i+j] = 0;                                                                                                                                                             
           ac[n*i+j] = A[n*i+j];                                                                                                                                                            
       }                                                                                                                                                                                    
       AInverse[n*i+i] = 1.;                                                                                                                                                                
   }                                                                                                                                                                                        
   fprintf(stderr,"%f %f %f %f\n",AInverse[0],AInverse[1],AInverse[2],AInverse[3] );                                                                                                                

// The current pivot row is iPass.                                                                                                                                                       
// For each pass, first find the maximum element in the pivot column.                                                                                                                    
   for (iPass = 0; iPass < n; iPass++)                                                                                                                                                      
   {                                                                                                                                                                                        
       imx = iPass;                                                                                                                                                                         
       for (irow = iPass; irow < n; irow++)                                                                                                                                                 
       { 
           if (fabs(A[n*irow+iPass]) > fabs(A[n*imx+iPass])) imx = irow;                                                                                                                    
       }                                                                                                                                                                                    
// Interchange the elements of row iPass and row imx in both A and AInverse.                                                                                                         
       if (imx != iPass)                                                                                                                                                                    
       {                                                                                                                                                                                    
           for (icol = 0; icol < n; icol++)                                                                                                                                                 
           {                                                                                                                                                                                
               temp = AInverse[n*iPass+icol];                                                                                                                                               
               AInverse[n*iPass+icol] = AInverse[n*imx+icol];                                                                                                                               
               AInverse[n*imx+icol] = temp;                                                                                                                                                 

               if (icol >= iPass)                                                                                                                                                           
               {                                                                                                                                                                            
                   temp = A[n*iPass+icol];                                                                                                                                                  
                   A[n*iPass+icol] = A[n*imx+icol];                                                                                                                                         
                   A[n*imx+icol] = temp;                                                                                                                                                    
               }                                                                                                                                                                            
           }                                                                                                                                                                                
       }                                                                                                                                                                                    

// The current pivot is now A[iPass][iPass].                                                                                                                                         
// The determinant is the product of the pivot elements.                                                                                                                             
       pivot = A[n*iPass+iPass];                                                                                                                                                            
       det = det * pivot;                                                                                                                                                                   
       if (det == 0)                                                                                                                                                                        
       {                                                                                                                                                                                    
           free(ac);                                                                                                                                                                        
           fprintf(stderr,"No inverse exit\n");                                                                                                                                                                        
       }                                                                                                                                                                                    

       for (icol = 0; icol < n; icol++)  
       {                                                                                                                                                                                    
// Normalize the pivot row by dividing by the pivot element.                                                                                                                     
           AInverse[n*iPass+icol] = AInverse[n*iPass+icol] / pivot;                                                                                                                         
           if (icol >= iPass) A[n*iPass+icol] = A[n*iPass+icol] / pivot;                                                                                                                    
       }                                                                                                                                                                                    

       for (irow = 0; irow < n; irow++)                                                                                                                                                     
// Add a multiple of the pivot row to each row.  The multiple factor                                                                                                                 
// is chosen so that the element of A on the pivot column is 0.                                                                                                                      
       {                                                                                                                                                                                    
           if (irow != iPass) factor = A[n*irow+iPass];                                                                                                                                     
           for (icol = 0; icol < n; icol++)                                                                                                                                                 
           {                                                                                                                                                                                
               if (irow != iPass)                                                                                                                                                           
               {                                                                                                                                                                            
                   AInverse[n*irow+icol] -= factor * AInverse[n*iPass+icol];                                                                                                                
                   A[n*irow+icol] -= factor * A[n*iPass+icol];                                                                                                                              
               }                                                                                                                                                                            
           }                                                                                                                                                                                
        }                                                                                                                                                                                    
    }                                                                                                                                                                                        

//    printf("%f %f %f %f\n",AInverse[0],AInverse[1],AInverse[2],AInverse[3] );                                                                                                              
    free(ac);                                                                                                                                                                                
    return AInverse;                                                                                                                                                                         
}                                                                                                                                                                                            


#if 1  // compare the result with one example from https://www.mathsisfun.com/algebra/matrix-inverse.html                                                                                                                                                                                   
int main()                                                                                                                                                                              {                                                                                                                                                                                            
   float a[4] = {3,3.5,3.2,3.6};                                                                                                                                                                      
   float *c;                                                                                                                                                                                
   c = MatrixInversion(a,2);                                                                                                                                                                
   printf("%f %f %f %f\n",c[0],c[1],c[2],c[3]);                                                                                                                                             
   free(c);
}                                          
#endif

REFERENCE:
list above.

Sunday, October 14, 2018

My linux command and setting collection



mostly from https://stackoverflow.com

nohup command >/dev/null 2>&1 &

jobs -l

ps -f -U

ps -ef | grep "command name"


history #show history command

fc [-e true] pid1 pid2 #repeat command with pid1 to pid2

copy between terminal

a) gvim -v
 In editor :echo has("clipboard")
set clipboard=unnamedplus


b)
esc m a
esc m b
:'a,'b w! xfer
ESC :r xfer


Thursday, October 11, 2018

The solution of cosmic ray propagation equation



transport equation

\[ \nabla  \cdot (D \nabla N_e) + \frac{\partial}{\partial E}(\frac{dE}{dt}N_e) + Q_e = \frac{\partial N_e}{\partial t} \]

energy change of particle
\[ E(t+dt) = E(t) + \frac{dE}{dt}dt \]
\[ dt = \frac{dE}{dE/dt} \]
\[ \int_{t_1}^{t_2} dt = \int_{E_1}^{E_2}  \frac{dE}{dE/dt} \]

if $dE/dt \equiv -b(E) = -aE^2 $  and $t_2>t_1$
\[ t_2 - t_1 = \frac{1}{a}[ \frac{1}{E_2} - \frac{1}{E_1}] \]
\[E(t_1) = \frac{E(t_2)}{1-a(t_2-t_1)E(t_2)} \]
and
\[E(t_2) = \frac{E(t_1)}{1+a (t_2-t_1)E(t_1)} \]

green function
\begin{equation}\nonumber
 G_e(\vec{r},\vec{r}',E,E',t,t') = \frac{1}{[\pi 4 f(E,E')]^{3/2}b(E)} \exp[\frac{-(\vec{r}'-\vec{r})^2}{4f(E,E')}]\cdot \delta(t'-t+h(E,E'))
\end{equation}

$f(E,E') = \int_{E'}^E  D(u)\frac{du}{du/dt} $ and $h(E,E') = \int_{E'}^E \frac{du}{du/dt}$

$\delta$ function
\[ \delta(g(x)) = \sum_i  \frac{\delta(x-x_i)}{|g^\prime(x_i)|} \]
$t>t'$    the time axis  ------t'---------t----->
$\delta(t' - t + h)$
\[ h = \int_{E'}^{E}  \frac{dE}{dE/dt} = - \frac{1}{a} [ \frac{1}{E^\prime} - \frac{1}{E} ]  \]
$g(E') = t'-t+h = t'-t + \frac{1}{a}[\frac{1}{E}-\frac{1}{E'}]$
$g(E') = t'-t + \frac{1}{a}[\frac{1}{E}-\frac{1}{E'}] = 0$
$g'(E') = \frac{1}{a{E^\prime}^2}$

\begin{equation}
\delta(t' - t + h)  =  \delta(t' - t  + [- \frac{1}{a}  (\frac{1}{E^\prime} - \frac{1}{E} )  ])
                                 =  \delta(E' -\frac{E}{1 -a (t-t')E}) \cdot [a (\frac{E}{1-a(t-t')E})^2]
\end{equation}

The solution of transport equation is given by
\begin{equation}\nonumber
\begin{split}
 N_e(\vec{r},E,t)  &= \int \int \int d\vec{r}' dE' dt' G_e(\vec{r},\vec{r}',E,E',t,t')Q_e(\vec{r}',E',t') \\
                              &= \int dt' \int d\vec{r}'  \frac{b(E')}{b(E)} \frac{Q_e(\vec{r}',E',t')}{(4\pi f(E,E'))^{3/2}} \exp{[\frac{-(\vec{r}' - \vec r)^2}{4f(E,E')}]}
\end{split}
\end{equation}
In this equation, the $E'$ is given by $E' =  \frac{E}{1-a(t-t')E}$.


In fact, the solution \[  N(\vec{r},E,t)  = \int dt' \int d\vec{r}'  \frac{b(E')}{b(E)} \frac{Q(\vec{r}',E',t')}{(4\pi f(E,E'))^{3/2}} \exp{[\frac{-(\vec{r}' - \vec r)^2}{4f(E,E')}]} \]
is general. It doesn't  depend on the assumption of the form of energy loss.
if we expand $\delta(t'-t + \int_{E'}^{E} \frac{dE}{dE/dt})$ directly, we can get the general solution. In this case $E'$ is a function of $E$ and $t-t'$.


Wednesday, October 10, 2018

Custom css style

CHANGE THE LINE HEIGHT OF YOUR TEXT
<span style=”line-height:150%;”>Text here.</span>
CHANGE THE SPACING BETWEEN LETTERS
<span style=”letter-spacing: 2px;”>Text here. </span>
CREATE SPACE AROUND YOUR TEXT
<span style=”padding:5px;”>Text here. </span>
<span style=”padding-bottom:20px;”>Text here. </span>
<span style=“padding-top:5px;padding-right:15px;”>Text here. </span>
CHANGE THE TEXT COLOR
<span style=”color:#CAE3DA”>Text here. </span>
PUTTING IT ALL TOGETHER
<span style=”font-size: 3em; color: #cae3da; letter-spacing: 5px; line-height: 200%; padding: 20px;”> This is just a few of the things the Span tag can do.</span>


REFEREENCE
THE ONE PIECE OF CODE EVERY BLOGGER SHOULD KNOW
http://saraheggers.com/2016/05/25/span/

Visit blogspot through ipv6

You need to add the ipv6 address of googleblog.blogspot.com into your host file.

for Linux
sudo vi /etc/hosts
and add this line in the file.
2404:6800:4008:c06::84 your blogger domain

You should check the ipv6 address, because it will be changed sometime.
Now you can visit your blogger.

REFEREBCE
For some reason, the reference is not showed.

Python symbol computation package sympy


SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python.

online sympy https://www.sympygamma.com/

from sympy import *

#define variable
x = Symbol('x')
y = Symbol('y')
a, b, c = symbols('a,b,c')

#expand
expand((x + y)**3)
expand(sin(x+y),trig=True)

#simplify
simplify((x + x*y) / x)

#limit
#limit(function, variable, point)
limit(sin(x)/x,x,0)
limit(1/x, x, oo)
limit( (sin(x+y) - sin(x))/y,y,0)

#diff
#diff(func,var,n)
diff(sin(x),x)
diff(sin(x),x,2)

#taylor series
#series(expr, var)
series(sin(x),x)

#integrate
integrate(x**2,x)
integrate(2*x + sinh(x), x)
integrate(exp(-x**2)*erf(x), x)
-----
integrate(x**3, (x, -1, 1))
integrate(exp(-x), (x, 0, oo))
integrate(exp(-x**2), (x, -oo, oo))

#factor
factor(x**2-1)

#solve equation
solve(x**4 - 1, x)
solve([x + 5*y - 2, -3*x + 6*y - 15], [x, y])

#matrix
A = Matrix([[1,x], [y,1]])

#dsolve
f, g = symbols('f g', cls=Function)
dsolve(f(x).diff(x, x) + f(x), f(x))

# real and positive variable
from sympy import symbols integrate
a,b,k=symbols('a,b,k',real=True,positive=True)
f=k**2/(k**2+a**2)/(1+k**2*b**2)**(5/6)
g=integrate(f,(k,-oo,oo))


REFERENCE
https://wizardforcel.gitbooks.io/scipy-lecture-notes/content/15.html