python - Using scipy.weave and GSL ODE -


after previous question trying solve odes using gsl. complicating factor want written in python , trying scipy.weave help.

using standard gsl ode example have following based on this example

import scipy.weave weave  time =0.0 y1 = [0.0,0.0] # define function   support_code=r'''   int  func (double t, const double y[], double f[],        void *params)  {    double mu = *(double *)params;    f[0] = y[1];    f[1] = -y[0] - mu*y[1]*(y[0]*y[0] - 1);    return gsl_success;  }   int  jac (double t, const double y[], double *dfdy,        double dfdt[], void *params)  {    double mu = *(double *)params;    gsl_matrix_view dfdy_mat       = gsl_matrix_view_array (dfdy, 2, 2);    gsl_matrix * m = &dfdy_mat.matrix;     gsl_matrix_set (m, 0, 0, 0.0);    gsl_matrix_set (m, 0, 1, 1.0);    gsl_matrix_set (m, 1, 0, -2.0*mu*y[0]*y[1] - 1.0);    gsl_matrix_set (m, 1, 1, -mu*(y[0]*y[0] - 1.0));    dfdt[0] = 0.0;    dfdt[1] = 0.0;    return gsl_success;  } '''   # define main  c_main = r'''  int  main (void)  {    double mu = 10;    gsl_odeiv2_system sys = {func, jac, 2, &mu};     gsl_odeiv2_driver * d =       gsl_odeiv2_driver_alloc_y_new (&sys, gsl_odeiv2_step_rk8pd,                   1e-6, 1e-6, 0.0);    int i;    double t1 = 100.0;      (i = 1; <= 100; i++)      {        double ti = * t1 / 100.0;        int status = gsl_odeiv2_driver_apply (d, &t, ti, y);         if (status != gsl_success)     {       printf ("error, return value=%d\n", status);       break;     }         time = t;      }     gsl_odeiv2_driver_free (d);    return 0;  } '''   compiler = 'gcc' vars = ['time','y'] libs = ['gsl','gslcblas','m'] headers = ['<stdio.h>','<gsl/gsl_errno.h>','<gsl/gsl_odeiv2.h>','<gsl/gsl_matrix.h>']   res = weave.inline(c_main, vars, compiler=compiler,                    libraries=libs, headers=headers,                    support_code = support_code)  print time 

which returns this horrible spew. don't have clue doing know should easy! trouble of examples of weave on web based on printf or short iterations.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -