Skip to content

Instantly share code, notes, and snippets.

@alexg228
Created November 19, 2010 05:07
Show Gist options
  • Save alexg228/706142 to your computer and use it in GitHub Desktop.
Save alexg228/706142 to your computer and use it in GitHub Desktop.
Laplace transform
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
double V[20000];
FILE *fp5 ;
V[1]=0;
V[2]=7;
V[3]=25;
V[4]=32;
V[5]=39;
V[6]=42;
V[7]=55;
V[8]=70;
V[9]=82;
V[10]=93;
V[11]=100;
int i;
int j;
int t;
int Max = 11;
double diff = 1;
fp5 = fopen("Laplace100.txt","w") ;
int main(void)
{
while (diff >= .001)
{
for(i=Max; i > 1; i--)
{ V[2*i-1] = V[i];
}
Max = 2*Max+1;
for(j=2; j< Max; j=j+2)
{ V[i] =.5*(V[i-1]+V[i+1]);
}
diff=((V[1]-V[2])/V[2]);
}
for(t=1; t<=Max; t++)
{
fprintf(fp5,"%6.31f %6.3lf\n", t, V[t]);
}
fclose(fp5);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment