/*PROGRAM JDIFFI2sq.C TO DEPICT A 2nd ORDER 2nd DEGREE DIFF.EQUATION*/
/* contributed by IVOR J LEWIS for Ch users*/
#include
#include
#include
#include
#include
time_t ltime;
int i,np=501,f;
float tlz,xoz,yoz,aoz,boz,coz,az,bz,cz,dz;
float mm,nn,pp,qq;
float amxy,aminy,avo,axo,ago,ato,tt1,tt2;
float fla;
float to,xo,yo,h;
float aa,bb,cc;
array double S[np],D[np],V[np],G[np],t[np],x[np],v[np],gl[np];
char buffer [11];
/* GRAPH TEXT DATA */
string_t title = "Displacement x,Velocity dx/dt & Acceleration d2x/dt2",
xlabel = "Time secs.",
ylabel = "Magnitude ";
class CPlot plot;
/* GRAPH TEXT DATA */
/* MAIN LOOP START */
main(argc, argv)
int argc;
char *argv[];
{
/* PRINT HEADERS & SET VARIABLES ******************************** */
{
printf("\n");
time(<ime);
printf(" Current Time %s\n",ctime(<ime));
printf(" SOLUTION TO DIFFERENTIAL EQUATION :- d2x/dt2 = A(dx/dt)^2 + Bx + C \n");
printf("\n\r");
}
/* ENTER aa & bb & cc VALUES ****************************** */
{
/* printf("\n"); */
printf(" USE TEST VALUES -2 -2 6 AND 10 secs \t");
printf("\n\r");
printf(" ENTER ' A B C' - VALUES \t");
scanf("%f %f %f",&aoz,&boz,&coz);
xo=0;
aa=aoz;
bb=boz;
cc=coz;
printf("\n");
printf(" Xo A B C \n");
printf(" %f\t %f\t %f\t %f\t %f\n",xo,aoz,boz,coz);
printf("\n");
/* printf(" %f\t %f\t %f\t %f\t %f\n",xo,aa,bb,cc); */
printf("\n");
/* exit(0); */
/* ENTER TIME DURATION FOR TRANSIENT */
float toz;
printf("\n");
printf(" ENTER 'TIME IN SECONDS' - VALUE \t");
scanf("%f",&toz);
printf("\n");
printf(" Xo A B C T \n");
printf(" %f\t %f\t %f\t %f\t %f\t %f\n",xo,aa,bb,cc,toz);
printf("\n");
/* exit(0); */
h=toz/501;
printf("\n");
/*CALCULATE VALUES ********************************************** */
float fla;
float to;
float t1;
float x1,x2,x3,x4;
float y1,y2,y3,y4;
float f1,f2,f3,f4;
xo=0;
yo=0;
t1=0;
x1=xo;
y1=yo;
f1=aa*y1+bb*x1+cc;
fla=f1;
printf(" INITIAL CONDITIONS......\n");
printf("\n");
printf("REF. t x dx/dt d2x/dt2 \n");
printf("0 %s \t\n");
printf(" %f\t",t1);
printf("%f\t",x1);
printf("%f\t",y1);
printf("%f\n",f1);
/* calculation loop */
for (i=1;i<=(np-1);i++)
{
x2 = x1 + h * y1 / 2.;
y2 = y1 + h * f1 / 2.;
f2 = aa*y2*y2 + bb*x2 + cc;
x3 = x1 + h * y2 / 2.;
y3 = y1 + h * f2 / 2.;
f3 = aa*y3*y3 + bb*x3 + cc;
x4 = x1 + h * y3 ;
y4 = y1 + h * f3 ;
f4 = aa*y4*y4 + bb*x4 + cc;
D[(i)] = x1 + h * (y1 + 2. * y2 + 2. * y3 + y4) / 6.;
V[(i)] = y1 + h * (f1 + 2. * f2 + 2. * f3 + f4) / 6;
G[(i)] = aa*V[i]*V[(i)] + bb*D[i] + cc;
S[(i)] = t1 + h;
t1 = S[(i)];
x1 = D[(i)];
y1 = V[(i)];
f1 = G[(i)];
printf("%d\t",i);
printf("%f\t",S[(i)]);
printf("%f\t",D[(i)]);
printf("%f\t",V[(i)]);
printf("%f\n",G[(i)]);
}
/* min g val nnp */
float nnp,tqp;
for(f=0; f <= (np-1); f ++)
{
tqp=G[(f)];
if ((nnp
|
|