intermediate values of y(t)

intermediate values of y(t)

I would like to solve ODE and get a function. not just a final i'd like to know a value of y(t) at all steps, for example incremented by 0.01.from my understanding the dodesol returns y(tmax) only. is there an efficient way to get the intermediate values?the routine that i was using before from numerical recipes used function evaluation during solving ode with adaptive step-size to interpolate the function so i can get an output for each increment of 0.01.

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

To obtain intermediate output is very straightforward. For example,

      dt =  1d-2
      do while(t+dt.le.t_end)
         CALL dodesol(ipar,n,t,t+dt,y,rhs_v_d_p,jacmat_v_d_p,
     +                h,hm,ep,tr,dpar,kd,ierr)
      end do

Hello there,

I am basically looking at the same question as the original poster, but in C, compiling with the Visual Studio 2010 command line.

I might be doing or overlooking something incredibly stupid, but all I get when looking for intermediate values is an error.

If I understand your post correctly, the solution is to call dodesol (or a subversion if one has a preference) at every time step and print out the value, i.e. run a loop around it. I am trying to do just that - but run into issues with the variable type, as it seems I cannot pass a simple double to the function...

The code looks like this:

double time = 0;

/* hybrid solver with automatic numerical Jacobi matrix computations */
/*dodesol_rkm9mkn(ipar,&n,&t,&t_end,y,rhs_v_d_p,&h,&hm,&ep,&tr,dpar,kd,&ierr); */

printf("DODESOL C example FAILED\n");
printf("dodesol_rkm9mkn routine exited with error code %4d\n",ierr);
return -1;

printf("\ndodesol_rkm9mkn results\n\n");
printf("Solution I =%17.14f, O2=%17.14f\n",y[0],y[11]);
printf("Solution RH=%17.14f, AH=%17.14f\n",y[7],y[8]);
printf("Solution SH=%17.14f, Rp=%17.14f\n",y[18],y[19]);
printf("CPU time=%f seconds\n", ((double)(time_end-time_begin))/CLOCKS_PER_SEC);
printf("Solution seems to be inaccurate. Probably, example FAILED...\n");
return -1;


return 0;

time = time = h;
}while(time <= t_end);

And the error I get is the following:

ODE_Setup.c(77) : error C2143: syntax error : missing ';' before 'type'
ODE_Setup.c(82) : warning C4047: 'function' : 'double *' differs in levels of indirection from 'time_t (__cdecl *)(time_t *)'
ODE_Setup.c(82) : warning C4024: 'dodesol_rkm9mkn' : different types for formaland actual parameter 4
ODE_Setup.c(111) : error C2440: '=' : cannot convert from 'double' to 'time_t (__cdecl *)(time_t *)'
ODE_Setup.c(112) : error C2440: '<=' : cannot convert from 'double' to 'time_t (__cdecl *)(time_t *)'

Many thanks :)

(I hope posting in this thread is appropriate, as it is the same topic)

OK, I have found one possible solution, but it has severe limitations.

Basically, write the current data at every iteration to a file. The limitation: if you have many iterations, the file size will be excessive and hard to analyze.

I attach my file with thecode to this edit, so ifanyboy wants to have a look, they can
My code for writing the current data is towards the end of the file.

You need something like this:

t=0; t_end=h;

}while(t_end <= t_final);

This will print the solution at t = h, 2h, 3h, ..., stopping at t = t_final.

I cannot make sense of the test that you applied:


If the solution of the ODE asymptotically approaches the values implied here for y[0] and y[1], the test would be meaningful as a termination criterion for the do{}..while() loop. I don't see how it can apply at any value of the independent variable t.

Leave a Comment

Please sign in to add a comment. Not a member? Join today