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 .

No comments: