Je reçois erreur suivante lorsque je compile mon code C . J'utilise Numerical Recipes 2nd ed. fonctions rk4() pour résoudre une équation différentielle de premier ordre.erreur lors de la résolution numériquement équation différentielle ordinaire dans C - erreur: attendu '=', ',', ';', 'asm' ou '__attribute__' avant '{' token
Je ne suis pas expert dans ce domaine. Toute aide sera grandement appréciée.
erreur est:
first_order_DE_RK4_example1.c:75: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
Code
est:
#include "nrutil.h"
#include <stdio.h>
#include <math.h>
void rk4(float y[], float dydx[], int n, float x, float h, float yout[],
void (*derivs)(float, float [], float []));
void (*derivs)(float, float[], float[]);
int main()
{
int n; float h; float x;
float y[1];
float dydx[1];
n=1;
h=0.2;
x=0;
y[0] = 1;
dydx[0] = 5.0;
void rk4(float y[], float dydx[], int n, float x, float h, float yout[],
void (*derivs)(float, float [], float []));
return 0;
}
void rk4(float y[], float dydx[], int n, float x, float h, float yout[],
void (*derivs)(float, float [], float []))
{
int i;
float xh,hh,h6,*dym,*dyt,*yt;
dym=vector(1,n);
dyt=vector(1,n);
yt=vector(1,n);
hh=h*0.5;
h6=h/6.0;
xh=x+hh;
for (i=1;i<=n;i++)
{
yt[i]=y[i]+hh*dydx[i];
(*derivs)(xh,yt,dyt);
}
for (i=1;i<=n;i++)
{ yt[i]=y[i]+hh*dyt[i];
(*derivs)(xh,yt,dym);
}
for (i=1;i<=n;i++)
{
yt[i]=y[i]+h*dym[i];
dym[i] += dyt[i];
}
(*derivs)(x+h,yt,dyt);
for (i=1;i<=n;i++)
{
yout[i]=y[i]+h6*(dydx[i]+dyt[i]+2.0*dym[i]);
}
free_vector(yt,1,n);
free_vector(dyt,1,n);
free_vector(dym,1,n);
}
void (*derivs)(float x, float y, float dydx)
{
float rhs;
rhs = 1-x+4*y;
}
'void (* dérivés) (float x, flottant y, float dydx) {...}' -> 'void derivés (float x, float y, float dydx) {...}' Ou supprime ça. – BLUEPIXY
Vous voulez au moins lire le chapitre 1.2 de ce livre, si vous ne prenez pas le temps de passer par un primaire C. – alk
lors de la compilation, activez toujours tous les avertissements, puis corrigez ces avertissements. Le code affiché provoque le compilateur à sortir environ trois douzaines de messages sur les problèmes. (pour 'gcc', utilisez au minimum:' -Wall -Wextra -pedantic' J'utilise aussi: '-Wconversion -std = gnu99) – user3629249