Saturday, March 25, 2017

binomial coefficient c code

 //binomial coefficient function  
 double Ni(  
         int deg,    //degree   
         int b       //for binomial  
     if( deg < 0 )  
         return 0.0;  
     else if ( deg == 0 )  
         return 1.0;  
         double temp = 1.0;  
         for(int i=1; i<=b;i++ ){  
             temp = temp* (double)(deg-i+1)/i;  
             printf("%f\n", temp);  
         return temp;  
 void main ()  
     int a=10, b=3;  
     double bin;  
     bin = Ni(a, b);  
     printf("%f\n", bin);  

comparison of secant and bisection method

 //example of function f(t), you can make any function you like  
 float f(float t)  
   return(((48.2291-30.6208*t-43) * (48.2291-30.6208*t-43)) + 35*t - 25.0);   
 void main()  
   float a = 0.1, b = 0.3, c = 0, e = 7.5e-3;  
   //a, b interval  
   //e error  
   int count = 1, n = 50; //n=maximum iteration  
   clock_t begin = clock();  
     c = (a*f(b) - b*f(a)) / (f(b) - f(a));  
     //c = b - (f(b)*(b-a) / (f(b) - f(a)));  
     printf("i No-%d  t=%f  d=%f\n",count,c, f(c));  
     if(count==n) break;  
   } while(fabs(f(c))&gt;e);  
   clock_t end = clock();  
   double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;  
   printf("time:%f", time_spent);  
   printf("\nThe required solution is %f\n",c);  
   printf("d = %f\n", f(c) + 25);  
   double fa, fb, fc;  
   a = 0.1; b = 0.3; c = 0; e = 7.5e-3;  
   count = 1;  
   clock_t begin2 = clock();  
     c = (a+b)/2;  
     fa = f(a);  
     fb = f(b);  
     fc = f(c);  
     if(fa*fc &lt; 0){  
       b = c;  
       a = c;  
     printf("i No-%d  t=%f  d=%f\n", count, c, fc);  
     if(count==n) break;  
   } while(fabs(fc)&gt;e);  
   clock_t end2 = clock();  
   double time_spent2 = (double)(end2 - begin2) / CLOCKS_PER_SEC;  
   printf("time:%f", time_spent2);  
   printf("\nThe required solution is %f\n",c);  
   printf("d = %f\n", fc + 25);  

Wednesday, November 30, 2016

dynamic 2d array using double data type

 #include <stdio.h>  
 #include <iostream>  
 int main() {  
  // dimensions  
  int N = 74;  
  int M = 3;  
  int i, j;  
  // dynamic allocation  
  double** ary = new double*[N];   //2d array  
  for(i = 0; i < N; ++i)         //↑  
    ary[i] = new double[M];      //1d array  
  for(i=0; i<N; i++){  
       for(j=0; j<M; j++){  
          ary[i][j] = i+j;  
          printf("point[%d][%d] = %.2f \n", i, j, ary[i][j]);  
  // free  
  for(i = 0; i < N; ++i)  
   delete [] ary[i];  
  delete [] ary;  
  return 0;  

//reffer to [http:]

Wednesday, November 2, 2016

passing and returning array in c language

#include                                         //standard library
#include                                        //standard mathematical library

//first derivative function
static double* GetDerivative(double t, double A[], double B[], double C[])       
                                                              //the function must be pointer double*
                                                              //for returning array

    //P・(t) = 3At^2 + 2Bt + C
    static double Pdot[3] = {0};                      //must be static
    Pdot[0] = 3*A[0]*t*t + 2*B[0]*t + C[0];
    Pdot[1] = 3*A[1]*t*t + 2*B[1]*t + C[1];
    Pdot[2] = 3*A[2]*t*t + 2*B[2]*t + C[2];
    return Pdot;                                       //return the array
//first derivative function

int main ()
    //P(t) = At3 + Bt2 + Ct + D
    ////P・(t) = 3At^2 + 2Bt + C
    double *derivative = 0;                        //must be pointer double *
                                                          //because the function is a pointer as well

    //double t[4] = {0.0, 0.25, 0.5, 0.75};
    double t[1] = {1};
    double A[] = {1, 2, 3};
    double B[] = {4, 6, 6};
    double C[] = {7, 8, 9};
    double D[] = {10, 11, 12};

    derivative = GetDerivative(t[0], A, B, C);    //put the return function to derivative
                                                              //plus make it as an array
                                                              //do not add [] even if it is array,
                                                              // unless you want to point the specific
                                                              // address of the array like t[0]
    printf("%ft2 + %ft + %f \n", derivative[0], derivative[1], derivative[2]);

    return 0;

//output 18.000000t2 + 26.000000t + 30.000000

Sunday, August 7, 2016

yodogawa fireworks!

Yodogawa fireworks is the biggest fireworks event in Osaka, I am glad that we came there because that was one of the best firework event I have ever came to visit. But, to be honest the smoke was a bit disturbing as you can see in the picture, sigh!


Our place was there (near minamikata station), we arrived there at 18:00 but we can still found a good spot easily. Although a bit far from the main spot, yet, quite a view. Next year, we want to try to find a spot at Yodogawa athletic park so we can get a good close spot.


Monday, July 18, 2016

the hanabi season has arrived!

Friday, February 12, 2016

test switching to japanese driving ilcense, tes ganti ke sim jepang, 外面切替試験 part 2

driving test

courses in fuchu driving license center, i got b course on february 9


tips and tricks for your driving test

  1. before driving
  1. put your belonging on the back seat, check back and front of your car (include under the car), check the road situation behind the car, open the door, say "onegaishimasu" to the instructor, go inside, close the door
  2. lock the door, set your seat position, wear seat belt, set the position of upper mirror, check the transmission lever (hold it and make sure it is in N or P position) and parking brake, step on the brake pedal and hold it, say "junbi dekimashita"
  3. turn the engine on while holding the brake, unlock the parking brake, set transmission into D, say "ikumasu", right blinker, check right mirror, right side of your car and check the road condition through right back window of the car, drive slowly to the right, and there you go

  1. while driving
  1. use left side lane, in a straight road, step the accelerator pedal to maximum speed that are allowed there (usually 40kmph), pull the pedal, brake slowly until before the curve. note: you are not allowed to step on the brake pedal while in the curve
  2. when you see "something annoying" on the way, you have to turn right blinker (about 30m before the "thing"), check right mirror, check through right back of the car, go to the right side, when you about to pass the "thing", turn your blinker to the left, check left mirror, check through left back window, go to the left side, continue to drive
  3. when you want to turn left you must turn your blinker to the left, check left mirror, check through left back window, go to the left so bike cannot pass through, in intersection or fork you must see right, left and right again (move your neck), then check your left back through left back window, when it is clear you can go to the left
  4. it is the same when you want to turn right
  5. when you see stop sign (tomare or 止まれ), you must stop (0kmph), check your right, left and right again, then go
  6. crank road and S road? you must practice! just place your right foot on the brake pedal, and move slowly
  7. when your test is about to finish turn the left blinker, check left mirror, check through left back window, go to the left so bike cannot pass through, make sure that the car is in align with the side walk, then stop
  8. set your seat position so you can go out easily, unlock the safety belt, lock the parking brake, set the transmission lever into P, turn the engine off, check right mirror, right side of your car and check the road condition through right back window of the car, say "arigatou gozaimashita", check behind you again, go out
  9. take your bag from the back seat, go to the instructor, take your exam result, say again "arigatou gozaimashita"


tes praktek menyetir

Tips dan trik tes praktek menyetir

  1. sebelum ngejalanin mobil
  1. masukin tas di kursi belakang, cek belakang mobil (bawah juga), depan mobil (bawah juga), cek belakang lagi, buka pintu,bilang onegaishimasu, masuk, tutup pintu
  2. kunci pintu, atur seat, pake sabuk pengaman, atur cermin diatas, cek gigi, rem tangan, injek rem, bilang "junbi dekimashita"
  3. sambil injek rem nyalain mesin, unlock rem tgn, masukin ke gigi D, blg "ikimasu", sen kanan, cek cermin kanan,cek belakang kanan (tengok kanan belakang via jendela belakang kanan), ambil kanan sedikit, jalan lah

  1. pas udah jalan
  1. jalan di jalur kiri, pas jalan lurus injek gas, sampe batas maksimum kecepatan (biasanya 40kmph), terus lepas gas, rem pelan pelan sampe mau belokan, tapi pas belokan ngga boleh ngerem, ngeremnya harus sebelum belokan
  2. pas ada barang di kiri, harus dihindari, dari jauh (sekitar 30m) sein kanan, liat spion kanan, liat kaca belakang kanan, ambil kanan, lewatin, pas sejajar sama benda yang dilewatin sein kiri, liat spion kiri, liat kaca belakang kiri, ambil kiri, lurus lagi
  3. kalau mau belok kiri dari jauh jauh harus sein kiri, liat spion kiri, liat kaca belakang kiri, ambil kiri supaya nutup jalan motor/sepeda, pas perempatan atau pertigaan, liat kanan, kiri, kanan (gerakin leher), setelah itu liat kaca belakang kiri (cek barang kali ada orang), kalo ngga ada jalan
  4. sama untuk kalau mau belok ke kanan
  5. jangan lupa kalau ada tanda tomare (止まれ) harus berenti dulu (0kmph), liat kanan, kiri, kanan, baru jalan
  6. kalo tips crank road atau S road, latian! sambil injek rem aja, terus jalanya pelan
  7. pas mau parkir setelah tes, sein kiri, liat spion kiri, liat kaca belakang kiri, ambil kiri, stop dipinggir, lurusin sejajar trotoar 
  8. atur seat supaya gampang keluar, lepas sabuk pengaman, rem tangan, pindahin gigi ke P, matiin mesin, kiat cermin kanan, liat belakang kanan, bilang "arigatou gozaimashita", keluar mobil, cek lagi belakang kanan
  9. ambil tas di kursi belakang, samperin instruktur, dapet kertas lulus atau ngga, bilang lagi "arigatou gozaimashita"