intermediate values of y(t)

intermediate values of y(t)

I would like to solve ODE and get a function. not just a final value.so 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 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

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)
         write(*,'(1x,F10.4,2x,1p,2D13.5)')t,y(1),y(2)
      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;

do{
/* 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); */
dodesol_rkm9mkn(ipar,&n,&t,&time,y,rhs_v_d_p,&h,&hm,&ep,&tr,dpar,kd,&ierr);
time_end=clock();

if(ierr!=0)
{
printf("\n========================\n");
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("t=%5.1f\n",t);
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("--------------------------------------------------------\n");
printf("CPU time=%f seconds\n", ((double)(time_end-time_begin))/CLOCKS_PER_SEC);
printf("========================================================\n\n");
if(fabs(y[0]-1.878e0)+fabs(y[1]+0.7436e0)>1.e-2)
{
printf("Solution seems to be inaccurate. Probably, example FAILED...\n");
return -1;
}

printf("\n========================\n");

return 0;

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

And the error I get is the following:

ODE_Setup.c
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)

EDIT:
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.
ODE_Setup.c

You need something like this:

t=0; t_end=h;
do{
dodesol_rkm9mkn(ipar,&n,&t,&t_end,...,&ierr);
if(ierr!=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(fabs(y[0]-1.878e0)+fabs(y[1]+0.7436e0)>1.e-2)

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.

登陆并发表评论。