This Image Shows the Vibration of a String Over time. It Goes up and comes back and so on..//Dhruv Balwada
#include"stdio.h"
#include"math.h"
int main()
{
float rho=0.01;
float T=40.0;
float x[101][3];
float c;
int i, k, l;
c=T/rho;
float c1=10*c;
float ratio=(c*c/(c1*c1));
FILE *fp;
fp=fopen("datanormal.dat", "w");
//Initialisation of the Array
for(i=0; i<3; i++)
{
for(k=0; k<101; k++)
x[k][i]=0;
}
//Initial Condition
for(i=0; i<81; i++){x[i][0]=0.00125*i;}
for(i=81;i<101;i++){x[i][0]=0.1-0.005*(i-80);}
//for(i=0; i<101; i++)
//{ l= sin(2*3.141*0.01*i);
//x[i][0]=0.001*l;
//}
//Loop to find the first Value
for(i=1; i<100; i++)
{
x[i][1]=x[i][0]+0.5*ratio*(x[i+1][0]+x[i-1][0]-2*x[i][0]);
}
//The Big time Loop Starts Here
for(k=1;k<1500; k++)
{
for(i=1; i<100; i++)
{
x[i][2]=2*x[i][1]-x[i][0]+ratio*(x[i+1][1]-2*x[i][1]+x[i-1][1]);
}
for(i=0; i<101; i++)
{
x[i][0]=x[i][1];
x[i][1]=x[i][2];
}
if((k%5)==0)
{
for(i=0; i<101; i++)
{
fprintf(fp,"%f",x[i][2]);
fprintf(fp,"\n");
}
fprintf(fp,"\n");
}
}//Big Time Loop Ends
}//Main Ends

lame :|
ReplyDelete