#include #include #include // for HUGE_VAL,M_PI #include #include #include "XYGraphTool.H" #ifdef USE_GTK #include #include "GTKGUI.H" #include "GTKGUIVirtualInput.H" #include "GTKWindow.H" #else #include "GUI.H" #include "GUIVirtualInput.H" #endif // changes: reformulate exact to follow the same pattern as the generated data, that is, store a // vector of "exact" following how the regular stuff is generated, except with an error tolerance // of DBL_EPSILON or so. Then we also need to change the formulae for the eqns we're solving to // match the formulae given in the assignment. enum HOW_STIFF{STIFF,NOT_STIFF}; HOW_STIFF how_stiff=NOT_STIFF; enum ITERATIVE_CORRECTION_METHOD{FUNCTIONAL_ITERATION,EXACT_JACOBIAN, FINITE_DIFFERENCE_JACOBIAN,DIAGONAL_JACOBIAN}; ITERATIVE_CORRECTION_METHOD iterative_correction_method= FUNCTIONAL_ITERATION; enum ERROR_FLAG{CONTROL_ASOLUTE_ERROR,CONTROL_RELATIVE_TO_CURRENT, CONTROL_RELATIVE_TO_MAX}; ERROR_FLAG error_flag=CONTROL_RELATIVE_TO_MAX; int ierror_flag=static_cast(error_flag); char *display_name=0; double winsize=0.5; double PI = 3.14159265358979323846264; double tstart=0.; double tstop=10*PI; double eps=sqrt(DBL_EPSILON); int number_coarse_steps=20; extern "C" { void F77NAME(epsode)( void (*diffun)(const int &n,const double &t,const double *y, double *ydot), void (*pederv)(const int &n,const double &t,const double *y, double *pd,const int &n0), const int &n,double &t0,double &h0,double *y0,const double &tout, const double &eps,const int &ierror,const int &mf,int &index); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // variables are in order: y[0] = x, y[1] = z, y[2] = y, y[3] = q void diffun(const int &n,const double &t,const double *y,double *ydot) { double R = sqrt(y[0]*y[0]+y[2]*y[2]); ydot[0] = y[1]; ydot[1] = y[1]/10. - y[0]*y[0]*y[0]+9.8*cos(t); // ydot[2] = y[3]; // ydot[3] = y[2]/(R*R*R); } void pederv(const int &n,const double &t,const double *y,double *pd, const int &n0) { pd[0] = 0.; pd[1] = 1.; pd[2] = -3. * y[0]*y[0]; pd[3] = -.1; } // double exact(const double &t) { return y_init*exp(rate*t); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: int main(int argc, char* argv[]){ #ifdef USE_GTK GTKWindow::gtkInit(argc,argv); #endif // double emax=-HUGE_VAL; // double emin=HUGE_VAL; // double ymax=max(exact(tstart),exact(tstop)); // double ymin=min(exact(tstart),exact(tstop)); double log10=log(10.); double emax=-HUGE_VAL; double emin=HUGE_VAL; Palette pal; XYGraphTool::WINDOW_TYPE::COLOR_MAP_TYPE cmap(&pal); XYGraphTool gt("tGuess versus QGuess","t","Q",0.,40.,-10.,5.5,&cmap,0, winsize); gt.newPage(); gt.setbgColor("white"); gt.setfgColor("black"); gt.drawAxes(); // XYGraphTool gt2("t versus Q","t","Q",0.,40.,-10.,5.5,&cmap,0, // winsize); // gt2.newPage(); // gt2.setbgColor("white"); // gt2.setfgColor("black"); // gt2.drawAxes(); clock_t start,end; double *errors=OPERATOR_NEW_BRACKET(double,9); double *times=OPERATOR_NEW_BRACKET(double,9); int n=2; double dt=(tstop-tstart)/static_cast(number_coarse_steps); double h0=dt; double t0=tstart; double h1=dt; double t1=tstart; double tout=tstart; double *yExact=OPERATOR_NEW_BRACKET(double,n); double *yGuess=OPERATOR_NEW_BRACKET(double,n); // initialization // variables are in order: x, z, y, q yExact[0]= 3.3; yExact[1] = 3.3; yGuess[0]= 3.3; yGuess[1] = 3.3; // yGuess[2] = 0; // yGuess[3] = sqrt(19); double tol; int counter = 0; int mf=10*static_cast(how_stiff) +static_cast(iterative_correction_method); int index=1; for (int i=1;i .000000001; tol /= 10.){ gt.newPage(); gt.setbgColor("white"); gt.setfgColor("black"); gt.drawAxes(); dt=(tstop-tstart)/static_cast(number_coarse_steps); h0=dt; h1=dt; t0=tstart; t1=tstart; tout=tstart; yGuess[0]= 3.3; yGuess[1] = 3.3; index = 1; gt.movePen(tstart,yGuess[0]); // gt2.movePen(yExact[0],yExact[2]); start = clock(); for (int i=1;i