|
|
|
bonjour à tous
j'ai un souci sur un programme.en fait j'ai des polynômes:
A(n)=a_0+a_1*n+a_2*n*n
F(n)=f_0+f_1*n+f_2*n*n
et -16<n<16
je dois donc generer aléatoirement des points a0,a1,a2 et f0,f1,f2 tels que A>0et 0<F<0.5
pour cela j'ai fais 2 fonctions:une fonction genere_signal et une fonction test_fonction dans laquelle je dois appeler la fonction genere_signal afin de generer de nouveaux points au cas où une de ces conditions ne sont pas satisfaites.
ma 1ere fonction (genere_signal à l'air de marcher) mais ma fonction ne marche pas du tout:ca me fait une erreur de segmentation.quelqu'un pourrait il m'aider ?merci d'avance.
ps:le programme en C doit etre compilé sous matlab d'où les mexfunction
ci-joint mes 2 programmes:
#include "mex.h"
#include <stdio.h>
#include<math.h>
#define taille_block 32
#define pi 3.14
/*void genere_signal(double *a_0,double *a_1,double *a_2,double *f_0,double *f_1,double *f_2,double *phi_0);*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int k,n,m;
double *a_0, *a_1, *a_2;
double *f_0, *f_1, *f_2;
double *phi_0;
double *A,*F,*phi,*S;
double *F_1,*F_2,*S_reel,*S_imaginaire;
double *Out_A,*Out_F,*Out_phi,*Out_F_1,*Out_F_2,*Out_S_reel,*Out_S_imaginaire,*Out_S;
int COMPLEX,i;
double S_1,S_2;
mexPrintf("debut de la fonction\n");
a_0=mxGetPr(prhs[0]);
a_1=mxGetPr(prhs[1]);
a_2=mxGetPr(prhs[2]);
f_0=mxGetPr(prhs[3]);
f_1=mxGetPr(prhs[4]);
f_2=mxGetPr(prhs[5]);
phi_0=mxGetPr(prhs[6]);
mexPrintf("recuperation des pointeurs\n");
plhs[0]=mxCreateDoubleMatrix(taille_block+1,1,mxREAL);
plhs[1]=mxCreateDoubleMatrix(taille_block+1,1,mxREAL);
plhs[2]=mxCreateDoubleMatrix(taille_block+1,1,mxREAL);
plhs[3]=mxCreateDoubleMatrix(1,1,mxREAL);
plhs[4]=mxCreateDoubleMatrix(taille_block+1,1,mxREAL);
plhs[5]=mxCreateDoubleMatrix(taille_block+1,1,mxREAL);
plhs[6]=mxCreateDoubleMatrix(taille_block+1,1,mxCOMPLEX);
plhs[7]=mxCreateDoubleMatrix(taille_block+1,1,mxCOMPLEX);
Out_A=mxGetPr(plhs[0]);
Out_F=mxGetPr(plhs[1]);
Out_F_1=mxGetPr(plhs[2]);
Out_F_2=mxGetPr(plhs[3]);
Out_phi=mxGetPr(plhs[4]);
Out_S_reel=mxGetPr(plhs[5]);
Out_S_imaginaire=mxGetPr(plhs[6]);
Out_S=mxGetPr(plhs[7]);
A=(double*)mxCalloc(taille_block+1,sizeof(double));
F=(double*)mxCalloc(taille_block+1,sizeof(double));
F_1=(double*)mxCalloc(taille_block+1,sizeof(double));
F_2=(double*)mxCalloc(taille_block+1,sizeof(double));
phi=(double*)mxCalloc(taille_block+1,sizeof(double));
S=(double*)mxCalloc(taille_block+1,sizeof(double));
S_reel=(double*)mxCalloc(taille_block+1,sizeof(double));
S_imaginaire=(double*)mxCalloc(taille_block+1,sizeof(double));
/*
Out_F=(double *)mxCalloc(taille_block+1, sizeof(double));
Out_F_1=(double *)mxCalloc(taille_block+1, sizeof(double));
Out_F_2=(double *)mxCalloc(taille_block+1, sizeof(double));
Out_phi=(double *)mxCalloc(taille_block+1, sizeof(double));
Out_S_reel=(double *)mxCalloc(taille_block+1, sizeof(double));
Out_S_imaginaire=(double *)mxCalloc(taille_block+1, sizeof(double));
Out_S=(double *)mxCalloc(taille_block+1, sizeof(double));
*/
A[0]=a_0[0];
A[1]=a_1[0];
A[2]=a_2[0];
mexPrintf("Vecteur A=\n");
for(k=0; k<3; k++)
{
mexPrintf("%lf\n",A[k]);
}
F[0]=f_0[0];
F[1]=f_1[0];
F[2]=f_2[0];
mexPrintf("Vecteur F=\n");
for(k=0; k<3; k++)
{
mexPrintf("%lf\n",F[k]);
}
phi[0]=phi_0[0];
mexPrintf("Vecteur phi_0=\n");
for(k=0; k<1; k++)
{
mexPrintf("%lf\n",phi[k]);
}
for(n=-taille_block/2;n<=taille_block/2;n++)
{
Out_A[n+taille_block/2]=a_0[0]+a_1[0]*n+a_2[0]*n*n;
Out_F[n+taille_block/2]=f_0[0]+f_1[0]*n+f_2[0]*n*n;
}
}
#include "mex.h"
#include <stdio.h>
#include<math.h>
#define taille_block 32
#define pi 3.14
void test_fonction_bis(double *A,double *F);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int K;
int d,t,n;
double *a_0,*a_1,*a_2;
double *f_0,*f_1,*f_2;
double *phi_0;
double * Out_A;
double * Out_F;
int Out_d,Out_t;
Out_A=mxGetPr(prhs[0]);
Out_F=mxGetPr(prhs[1]);
plhs[0]=mxCreateDoubleMatrix(taille_block+1,1,mxREAL);
plhs[1]=mxCreateDoubleMatrix(taille_block+1,1,mxREAL);
/*Out_d=mxGetPr(plhs[0]);
Out_t=mxGetPr(plhs[1]);*/
d=(int)mxCalloc(1,sizeof(int));
t=(int)mxCalloc(1,sizeof(int));
/* Out_A[n+taille_block/2]=0;
Out_F[n+taille_block/2]=0;*/
d=0;
for(n=-taille_block/2;n<=taille_block/2;n++)
{
if(Out_A[n+taille_block/2]< 0 )
{
/*la reponse est correcte */
Out_d=1;
break;
}
else
{
Out_A[n+taille_block/2]=a_0[0]+a_1[0]*n+a_2[0]*n*n;
}
}
t=0;
for(n=-taille_block/2;n<=taille_block/2;n++)
{
if(0<Out_F[n+taille_block/2]< 0.5 )
{
Out_t=1;
break;
}
else
{
Out_F[n+taille_block/2]=f_0[0]+f_1[0]*n+f_2[0]*n*n;
}
}
return;
}
|
|