ffnajia
Messages postés
30
Date d'inscription
mercredi 12 avril 2006
Statut
Membre
Dernière intervention
17 avril 2007
26 juil. 2006 à 10:09
Bonjour ;
Merci beaucoup pour vos réponses, mais malheureusement je trouve ça trés compliquer!!
voila mon programme: mon problème est dans la partie en bleu, je veux qu'il vide à chaque fois le tableau capi??
#include
#include<cmath>
using namespace std;
double puis(double x, double y){
double z;
z=exp(y*log(x));
return z;
}
double fonct(double x,double n, int i){
double y;
if(i==0) y=3*puis(x,n);
if(i==1) y=1;
if(i>1) y=0;
return y;
}
double uti(double x, int i){
double y;
if(i==0) y=log(x);
if(i==1) y=1./x;
return y;
}
double grad(double delta, double x, double z, int n, int j, double h){
double y;
y=-((h*exp((n-delta)*j*h))/x)-z*h;
return y;
}
int main(){
double delta,h,lambda,capifinal,utilite,ro,epsi,capi0,cd,cg;
double consom,cap,cap1,alpha,gama,taux,d,p;
int nb,n,m,ok,iter,compter,number,Maxiter,Maxcompter;
FILE* Ecriture = fopen("donnees_E","w");
fprintf(Ecriture,"%lf %lf %lf %lf %lf %lf %lf %lf %d %d %d %d",.005,.05,100000.,.8,20.,0.,0.1,0.1,100,8,50,80);
fclose(Ecriture);
FILE* Lecture = fopen("donnees_E","r");
fscanf(Lecture,"%lf %lf %lf %lf %lf %lf %lf %lf %d %d %d %d",&alpha,&gama,&capi0,&delta,&lambda,&capifinal,&ro,&epsi,&nb,&n,&Maxiter,&Maxcompter);
fclose(Lecture);
double* capi = new double [nb];
double* R=new double [nb];
double* S=new double [nb];
double* I=new double [nb];
double* mu = new double [nb];
double** conso = new double* [Maxiter+1];
for(int j=0;j<Maxiter;j++) {conso[j]=new double [nb];}
h=1./nb;
cg=0.; cd=40*capi0;
capi[0]=capi0;
compter=0;
cap1=capi[0];
taux=.05; d=10.; p=10.;
S[0]=1000.; I[0]=1.; R[0]=0.;
while(compter<Maxcompter and cap1-capifinal>epsi){
consom=cg+((cd-cg)/2.);
for(int i=0;i<nb-1;i++){
// if int i=0;
capi[i+1]=capi[i]+h*(fonct(capi[i],.3,0)*fonct(S[i]+R[i],.7,0)-consom-d*I[i]-p*taux*S[i]);
S[i+1]=S[i]*(1-h*(alpha*I[i]+taux));
I[i+1]=I[i]*(1+h*(alpha*S[i]-gama));
R[i+1]=R[i]+h*(gama*I[i]+taux*S[i]);
// if(capi[i+1]>0.){i+=1;}
// else break;
printf("%d %lf %lf %lf \n ",i,capi[i],capi[i+1],capi[nb-1]);
}
if(capi[nb-1]>capifinal)cg=consom,cap1=capi[nb-1];
else cd=consom, cap1=capi[0];
printf("%lf\n",consom);
// printf("%lf\n",S[0]);
// printf("%lf\n",capi[0]);
compter++;
printf("\n%d\n",compter);
}
getchar();
return 0;
}
bonne journée.
Merci à tous
Najia