Showing posts with label it. Show all posts

Agribusiness × AI

 Agribusiness × AI

The role of AI in Agribusiness and study case in our lab

 Laboratory of Management Informatics




dynamically allocated array

 #include <stdio.h>  
 #include <stdlib.h>  
   
 void main()  
 {  
     double *ar; //will be your array  
     double elem[] = {0.1, 0.2 ,0.3 ,0.4 ,0.5};   
     int num = 5, i;  
   
     printf("array number: %d\n", num);  
     for(i=0; i<num; i++)  
         printf("[%d]:%.2f\n", i, elem[i]);  
   
     printf("lets double it and put in your new array using malloc\n");  
     printf("--\n");  
   
     ar = malloc(sizeof(double)*num); //allocate the memory for your array  
   
     for(i=0; i<num; i++){  
       *(ar+i) = elem[i] * 2;  
     }  
   
     for(i=0; i<num; i++)   
         printf("array[%d]=%.2f\n", i, ar[i]);  
   
 free(ar); //must free the memorry allocation after using it  
 } 
 
result:
-------------- 
 array number: 5
[0]:0.10
[1]:0.20
[2]:0.30
[3]:0.40
[4]:0.50
lets double it and put in your new array using malloc
--
array[0]=0.20
array[1]=0.40
array[2]=0.60
array[3]=0.80
array[4]=1.00 

binomial coefficient c code

 #include<stdio.h>  
   
 //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;  
     else{  
         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("\n=============\n");  
     printf("%f\n", bin);  
 }  

comparison of secant and bisection method

   
 #include<stdio.h>  
 #include<math.h>  
 #include<time.h>  
   
 //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  
     
   //  
   //secant  
   //  
   clock_t begin = clock();  
   do  
   {      
     c = (a*f(b) - b*f(a)) / (f(b) - f(a));  
     //c = b - (f(b)*(b-a) / (f(b) - f(a)));  
     a=b;  
     b=c;  
     printf("i No-%d  t=%f  d=%f\n",count,c, f(c));  
     count++;  
     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);  
   
   //  
   //bisection  
   //  
   double fa, fb, fc;  
   a = 0.1; b = 0.3; c = 0; e = 7.5e-3;  
   count = 1;  
   clock_t begin2 = clock();  
   do{  
     c = (a+b)/2;  
     fa = f(a);  
     fb = f(b);  
     fc = f(c);  
   
     if(fa*fc &lt; 0){  
       b = c;  
     }  
     else{  
       a = c;  
     }  
     printf("i No-%d  t=%f  d=%f\n", count, c, fc);  
     count++;  
     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);  
   
    
 }  

download file using batch process

How to do the batch download
1. Copy link location of file that you want to download, eg: http://nodai.ac.jp/abcd.txt or anything
2. Make new file with .sh (shell) extension, can be made using notepad or another text editor, eg: test.sh
3. inside the test.sh file If you are using linux/cygwin type wget if you want to download more than one file, just hit enter after the first link and type wget if you are using machintosh change wget with curl -O , eg: curl -O http://nodai.ac.jp/abcd.txt
4. open terminal/cygwin, and then change directory *cd* to the place you saved the .sh file and then hit enter (eg: assume that the file is located in desktop under the download folder, so you need to type cd /Desktop/download/)
5. Then make sure that the file test.sh is in that directory (folder) by typing ls and hit enter, ls is used to list the file in that directory
6. If the file is there, in the terminal/cygwin type chmod a+x test.sh, chmod: change mode, a+x: all user plus x, and the name of file
7. Type ./test.sh, command of ./ has function to process the executable file
8. Within seconds the terminal/cygwin will download your file automatically, the file will be downloaded to the directory where .sh is belong to, in this case the file will be downloaded to /Desktop/download

バッチ処理でのファイルダウンロード
1。ダウンロードファイルのリンク先のコピー、例 http://nodai.ac.jp/abcd.txt
2。.sh ファイルを作る、.shファイルはノートパッドあるいはテキストエディターで作れる。例 test.sh
3。test.sh の中に タイプすることが必要、リナクス/シッグウィンを使う場合は wget <リンク先ファイル>、macを使う場合は wget の代わりに curl -O をタイプする、例 curl -O http://nodai.ac.jp/abcd.txt
4。ターミナル/シッグウィンを開き、test.sh のディレクトリにディレクトリチェンジを行う、例もしそのファイルが/Desktop/download/に存在したら cd /Desktop/download/
5。そのディレクトリの内容を確認 ls をタイプし、エンターたたく。
6。ファイル確認されたら、chmod a+x test.sh をタイプする。
7。終わったら ./test.sh をタイプする。
8。ダウンロードが始まる。ダウンロードファイルは /Desktop/download/ に保存される。