Wednesday, July 2, 2008

without finding the meaning from dictionary,  I think its called array in english.

okay, our mission is simple. How to make a set of data and put into a  math function,  calculate, and save the result in one file.

first of all built a simple linear graph function like y=mx+c, then, define all the coefficient. Then, built step by step.

1. put the header
2. define all the coefficient
3. built the input form
4. built the save data form
5. built the calculation function 

thats all. the most important part here is to define the array "hairetsu" means the range of data. for example input x=1,2,3....till 100, we can write it 


int i <<
double x1[1001] <<

then, 

don`t forget to define x1[i] = x;

here is the script for this program

/*======================================================================
linear graf data awis ver.
File Name : 練習1.c
Version : 1.00
Date : 2008.6.25
Programed by awis85
========================================================================*/
//------ヘッダー-------
#include
#include
#include
#include
#include
#include


//-------変数定義--------
int i; //parameter

double  x = 0.0; //X軸
double y = 0.0; //Y軸
double = 0.0; //傾き
double = 0.0; //係数
double x1[1001];
double Y1[1001];

//------データ入力と取り込み---------
void input(void)
{
printf("傾きを入力[1/cm]\n");
scanf("%lf",&m);printf("\n");

printf("定数を入力[cm]\n");
scanf("%lf",&c);printf("\n");

}

//---データ保存---
void save_data(void)
{
char name[20];
FILE *fp;

printf("Input Data Name : ");
scanf("%s",name);
strcat (name,".dat");

fp=fopen(name,"w"); //エラーメッセージ
if (fp==NULL){
printf("File Cannot Open");
exit(1);
}
for(i=0;i<= 100;i++){
fprintf(fp,"%10.7f %10.7f\n",x1[i],Y1[i]);
}

fclose(fp);
printf("出力終了  \n");
}

//----------計算ここから-----------
void main(void)
{
input();
for(i=0;i<=100;i++){
x = i * 1;
y = (m * x) + c;

x1[i] = x;
Y1[i] = y;

printf(" x= %lf y= %f \n",x,y);
}
printf("計算終了\n");
save_data();
}

Tuesday, July 1, 2008


#include
#include // for math function and symbols
#include
#include       //to get memory management funtion 
#include  //memory and string functions
#include          // Defines structs, unions, macros, and functions for dealing with MSDOS and the Intel iAPX86 microprocessor family.


//-------変数定義--------
int i;

double time = 0.0; //時間
double x = 0.0; //変位
double m = 0.0; //質量
double c = 0.0; //減衰係数
double k = 0.0; //バネ定数
double x0 = 0.0; //初期変位
double h = 0.01; //刻み幅
double myu = 0.0;
double x1[1000001]; //配列
double T1[1000001];
double p = 0.0;
double y = 0.0;
double fai = 0.0;
double v0 = 0.0;

//------データ入力と取り込み---------
void torikomi(void)
{
printf("質量を入力[kg]\n");
scanf("%lf",&m);printf("\n");

printf("ばね定数を入力[kg/m]\n");
scanf("%lf",&k);printf("\n");

printf("ダンパ定数を入力[kg/(m/s)]\n");
scanf("%lf",&c);printf("\n");

printf("初期変位を入力[m]\n");
scanf("%lf",&x0);printf("\n");
}

//---データ保存---
void save_data(void)
{
char name[20];
FILE *fp;

printf("Input Data Name : ");
scanf("%s",name);
strcat (name,".dat");

fp=fopen(name,"w"); //エラーメッセージ
if (fp==NULL){
printf("File Cannot Open");
exit(1);
}
for(i=0;i<= 10000;i++){
fprintf(fp,"%10.7f %10.7f\n",T1[i],x1[i]);
}

fclose(fp);
printf("出力終了  \n");
}

//----------計算ここから-----------
void main(void)
{
torikomi();
i   = 0;
myu = c * 0.5 / m;
p   = sqrt(k / m);
y   = p*p-myu*myu;
fai = atan((v0+myu*x0)/(x0*sqrt(y)));
for(i=0;i<=10000;i++){
time = i * h;
x = exp(-myu * time) * sqrt(pow(x0,2)+pow(((v0 + myu*x0)/sqrt(y)),2))*cos(sqrt(y)*time-fai);
x1[i] = x;
T1[i] = time;
printf("time= %lf x= %f \n",time,x);
}
printf("計算終了\n");
save_data();
}


this is the program`s language for the last week model.  Actually i got this script from Razi which he got from his senior. it`s almost impossible for me to write from beginning .

Wednesday, June 18, 2008

learning C language


#include

int main(){

printf ("hello world!\n");
printf ("im awis....penat la ari nih..\n");

    

return 0;

}

our mission is to creating this simulation program