[Ubuntu-BD] The compiled program in g++ didn't give complete output in the terminal or any output file.

Md Ashickur Rahman Noor ashickur.noor at gmail.com
Thu Jan 26 14:46:55 UTC 2012


@Pavel Sayekat

First please use http://paste.ubuntu.com/ for submitting code (though it is
not a rules, I learned it from IRC, it is a good practice). I think it is
very much helpful. I have paste it here <http://paste.ubuntu.com/817696/>.

I think is not a problem of g++. You may have made some logical error in
your code.
----------------------------------------------------------
Dedicated Linux Forum in Bangladesh <http://goo.gl/238Ck>
2048R/89C932E1 <http://goo.gl/TkP5U>
Volunteer, FOSS Bangladesh <http://fossbd.org/> && Mozilla
Reps<https://wiki.mozilla.org/ReMo>
01611151550




On 26 January 2012 20:34, Pavel Sayekat <pavelsayekat at gmail.com> wrote:

> I did a c++ code for solving a third order D.E. as follows:
>
> /*By this program we will find out the initial condition.
>
> /*The initial condition (when t=0) of the third order nonlinear ODE*/
>
> /*Date: 23.01.2012*/
>
> #include <stdio.h>
>
> #include <math.h>
>
> // FILE *fp;
>
>  #define N 3
>
>  int rk();
>
>  int sub();
>
>  int i, m;
>
>  float F[N], K[4][N], temp[N],V[N], T_limit=5.1, h=0.5, T=0., e=0.1, c1,
> c2, c3, lm=.8, x, x0, x1, x2;
>
>   // Y[N] is the initial value of the dependent variable of our original
> equation.
>
>   // T (time) is the independent variable of our original equation.
>
>   // K is used for iteration of Runge Katta Method.
>
>   // T_limit is used as the final value of T (time)
>
> int main()
>
>  {
>
>  float a0=0.4, b0=0.2, c0=0.1;
>
>        float y0, y1, y2, z0, z1, z2;
>
>  float k,j;
>
>  float r, m1, m2, m3, m4, m5, m6, m7, m8, m9;
>
>  float p1, p2, p3;
>
>  float q1, q2;
>
>  for (j=2.5;j<=10;j=j+0.2)
>
>  {
>
>  printf("\n");
>
>  k=j;
>
> // printf("Enter a +ve value of the root, k=");
>
>      //k means lamda
>
> // scanf("%f", &k);
>
>  //r=-1/(k*k);
>
>         //m1=2/(k*k*k);
>
>   m2=18/pow(k,4);
>
>   m3=72/pow(k,5);
>
>   m4=120/pow(k,6);
>
>   //m5=1/pow(k,3);
>
>   //m6=12/pow(k,4);
>
>   m7=m3;
>
>   m8=240/pow(k,6);
>
>   m9=360/pow(k,7);
>
>             p1=-1/(k*k);
>
>           p2=-6/pow(k,3);
>
>           p3=-12/pow(k,4);
>
>     q1=-2/pow(k,2);
>
>     q2=-6/pow(k,3);
>
>  y0=a0;
>
>  z0=e*(b0*c0*m4+c0*c0*m9);
>
>  x0=y0+z0;
>
>  y1=-k*a0+e*(a0*a0*p1+a0*b0*p2+(b0*b0+2*c0*a0)*p3)+b0;
>
>  z1=e*(-2*k*(b0*c0*m4+c0*c0*m9)+b0*c0*m3+c0*c0*m8);
>
>  x1=y1+z1;
>
>
>  y2=k*k*a0-3*e*k*(a0*a0*p1+a0*b0*p2+(b0*b0+2*c0*a0)*p3)-2*k*b0+2*e*(a0*b0*q1+(b0*b0+2*c0*a0)*q2)+2*c0;
>
>
>  z2=e*(4*k*k*(b0*c0*m4+c0*c0*m9)-4*k*(b0*c0*m3+c0*c0*m8)+2*b0*c0*m2+2*c0*c0*m7);
>
>        x2=y2+z2;
>
>  printf("\n\t\t x0=%f \n\t\t x1=%f \n\t\t x2=%f", x0, x1, x2);
>
>  printf("\n");
>
>  printf("\n");
>
>  sub();
>
>  }
>
> return 0;
>
> }
>
>  int sub()
>
>  {
>
>  c1=-3.0*lm; //sum of the A.U. roots.
>
>  c2=3.0*lm*lm; //sum of the product of the roots taken two at a time
>
>  c3=-lm*lm*lm; //product of the roots
>
> // fp=fopen("learn1.dat", "w");
>
>  V[0]=x0;
>
>  V[1]=x1;
>
>  V[2]=x2;
>
> // printf("initial value\n");
>
> // for (i=0; i<N; i++)
>
> // {
>
> // printf("Y[%d]=",i);
>
> // scanf("%f", (Y+i));
>
> // }
>
>  do
>
>  {
>
>  printf ("%.2f\t",T);
>
> // fprintf(fp, "%.2f\n", T);
>
>  x=V[0];
>
>  for(i=0; i<N; i++)
>
>  {
>
>  temp[i]=V[i];
>
>  printf("%f\t",V[i]);
>
>  }
>
>  printf("%f\n",x);
>
> // fprintf(fp, "%f\n", x);
>
>  for(m=0; m<4; m++)
>
>  {
>
>  F[0]=V[1];
>
>  F[1]=V[2];
>
>  F[2]=-c3*V[0]-c2*V[1]-c1*V[2]-e*V[0]*V[0]*V[0];
>
>  rk();
>
>  }
>
>  } while(T<T_limit+h);
>
>  return 0;
>
>  }
>
>  int rk()
>
>  {
>
>  for(i=0; i<N; i++)
>
>  {
>
>  K[m][i]=F[i];
>
>  if (m==0 || m==1)
>
>  V[i]=temp[i]+.5*h*K[m][i];
>
>  else if(m==2)
>
>  V[i]=temp[i]+h*K[m][i];
>
>  else V[i]=temp[i]+(K[0][i]+2*K[1][i]+2*K[2][i]+K[3][i])*h/6.;
>
>  }
>
>  if (m==0 || m==2)
>
>  T=T+.5*h;
>
>  return 0;
>
>  }
>
> But the compiled program gave me this
>
>   x0=0.401573
>   x1=-0.814725
>   x2=1.773615
>
> 0.00 0.401573 -0.814725 1.773615 0.401573
> 0.50 0.369061 1.085164 6.471668 0.369061
> 1.00 2.058680 6.524188 16.426159 2.058680
> 1.50 7.990735 18.327394 27.232946 7.990735
> 2.00 18.454220 7.876439 -167.319901 18.454220
> 2.50 -28.053253 -251.635757 -664.048889 -28.053253
> 3.00 556.427917 14110.076172 153872.875000 556.427917
> 3.50 -71204488.000000 -11171593216.000000 1046708024770560.000000
> -71204488.000000
> 4.00 24474019397295355228848128.000000 -inf -inf
> 24474019397295355228848128.000000
> 4.50 -nan -nan -nan -nan
> 5.00 -nan -nan -nan -nan
> 5.50 -nan -nan -nan -nan
>
>   x0=0.400964
>   x1=-0.890924
>   x2=2.096703
>
> 6.00 0.400964 -0.890924 2.096703 0.400964
>
>   x0=0.400612
>   x1=-0.968352
>   x2=2.455168
>
> 6.50 0.400612 -0.968352 2.455168 0.400612
>
>   x0=0.400401
>   x1=-1.046550
>   x2=2.847923
>
> 7.00 0.400401 -1.046550 2.847923 0.400401
>
>   x0=0.400270
>   x1=-1.125250
>   x2=3.274284
>
> 7.50 0.400270 -1.125250 3.274284 0.400270
>
>   x0=0.400187
>   x1=-1.204286
>   x2=3.733802
>
> 8.00 0.400187 -1.204286 3.733802 0.400187
>
>   x0=0.400131
>   x1=-1.283556
>   x2=4.226174
>
> 8.50 0.400131 -1.283556 4.226174 0.400131
>
>   x0=0.400094
>   x1=-1.362993
>   x2=4.751190
>
> 9.00 0.400094 -1.362993 4.751190 0.400094
>
>   x0=0.400069
>   x1=-1.442549
>   x2=5.308702
>
> 9.50 0.400069 -1.442549 5.308702 0.400069
>
>   x0=0.400051
>   x1=-1.522195
>   x2=5.898601
>
> 10.00 0.400051 -1.522195 5.898601 0.400051
>
>   x0=0.400039
>   x1=-1.601908
>   x2=6.520808
>
> 10.50 0.400039 -1.601908 6.520808 0.400039
>
>   x0=0.400029
>   x1=-1.681673
>   x2=7.175263
>
> 11.00 0.400029 -1.681673 7.175263 0.400029
>
>   x0=0.400023
>   x1=-1.761478
>   x2=7.861919
>
> 11.50 0.400023 -1.761478 7.861919 0.400023
>
>   x0=0.400018
>   x1=-1.841314
>   x2=8.580742
>
> 12.00 0.400018 -1.841314 8.580742 0.400018
>
>   x0=0.400014
>   x1=-1.921176
>   x2=9.331702
>
> 12.50 0.400014 -1.921176 9.331702 0.400014
>
>   x0=0.400011
>   x1=-2.001059
>   x2=10.114779
>
> 13.00 0.400011 -2.001059 10.114779 0.400011
>
>   x0=0.400009
>   x1=-2.080957
>   x2=10.929955
>
> 13.50 0.400009 -2.080957 10.929955 0.400009
>
>   x0=0.400007
>   x1=-2.160870
>   x2=11.777213
>
> 14.00 0.400007 -2.160870 11.777213 0.400007
>
>   x0=0.400006
>   x1=-2.240794
>   x2=12.656545
>
> 14.50 0.400006 -2.240794 12.656545 0.400006
>
>   x0=0.400005
>   x1=-2.320727
>   x2=13.567937
>
> 15.00 0.400005 -2.320727 13.567937 0.400005
>
>   x0=0.400004
>   x1=-2.400669
>   x2=14.511384
>
> 15.50 0.400004 -2.400669 14.511384 0.400004
>
>   x0=0.400003
>   x1=-2.480617
>   x2=15.486879
>
> 16.00 0.400003 -2.480617 15.486879 0.400003
>
>   x0=0.400003
>   x1=-2.560571
>   x2=16.494415
>
> 16.50 0.400003 -2.560571 16.494415 0.400003
>
>   x0=0.400002
>   x1=-2.640530
>   x2=17.533987
>
> 17.00 0.400002 -2.640530 17.533987 0.400002
>
>   x0=0.400002
>   x1=-2.720493
>   x2=18.605595
>
> 17.50 0.400002 -2.720493 18.605595 0.400002
>
>   x0=0.400002
>   x1=-2.800460
>   x2=19.709229
>
> 18.00 0.400002 -2.800460 19.709229 0.400002
>
>   x0=0.400001
>   x1=-2.880430
>   x2=20.844889
>
> 18.50 0.400001 -2.880430 20.844889 0.400001
>
>   x0=0.400001
>   x1=-2.960402
>   x2=22.012573
>
> 19.00 0.400001 -2.960402 22.012573 0.400001
>
>   x0=0.400001
>   x1=-3.040378
>   x2=23.212278
>
> 19.50 0.400001 -3.040378 23.212278 0.400001
>
>   x0=0.400001
>   x1=-3.120355
>   x2=24.444002
>
> 20.00 0.400001 -3.120355 24.444002 0.400001
>
>   x0=0.400001
>   x1=-3.200335
>   x2=25.707743
>
> 20.50 0.400001 -3.200335 25.707743 0.400001
>
>   x0=0.400001
>   x1=-3.280316
>   x2=27.003500
>
> 21.00 0.400001 -3.280316 27.003500 0.400001
>
>   x0=0.400001
>   x1=-3.360298
>   x2=28.331272
>
> 21.50 0.400001 -3.360298 28.331272 0.400001
>
>   x0=0.400001
>   x1=-3.440282
>   x2=29.691055
>
> 22.00 0.400001 -3.440282 29.691055 0.400001
>
>   x0=0.400000
>   x1=-3.520268
>   x2=31.082853
>
> 22.50 0.400000 -3.520268 31.082853 0.400000
>
>   x0=0.400000
>   x1=-3.600254
>   x2=32.506660
>
> 23.00 0.400000 -3.600254 32.506660 0.400000
>
>   x0=0.400000
>   x1=-3.680242
>   x2=33.962475
>
> 23.50 0.400000 -3.680242 33.962475 0.400000
>
>   x0=0.400000
>   x1=-3.760230
>   x2=35.450302
>
> 24.00 0.400000 -3.760230 35.450302 0.400000
>
> But every iteration should give me a little more detailed output like the
> first one, for instance:
>
>   x0=0.401573
>   x1=-0.814725
>   x2=1.773615
>
> 0.00 0.401573 -0.814725 1.773615 0.401573
> 0.50 0.369061 1.085164 6.471668 0.369061
> 1.00 2.058680 6.524188 16.426159 2.058680
> 1.50 7.990735 18.327394 27.232946 7.990735
> 2.00 18.454220 7.876439 -167.319901 18.454220
> 2.50 -28.053253 -251.635757 -664.048889 -28.053253
> 3.00 556.427917 14110.076172 153872.875000 556.427917
> 3.50 -71204488.000000 -11171593216.000000 1046708024770560.000000
> -71204488.000000
> 4.00 24474019397295355228848128.000000 -inf -inf
> 24474019397295355228848128.000000
> 4.50 -nan -nan -nan -nan
> 5.00 -nan -nan -nan -nan
> 5.50 -nan -nan -nan -nan.
>
> --
> Ubuntu Bangladesh
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-bd
>


More information about the ubuntu-bd mailing list