Does anybody have any idea why this code doesnt work?
the error is in the ACHA_FI_P() function... the problem is I couldnt debug this code using dev c++, anybody know a good debugger?
the ACHA_FI_P function is to resolve 2 equations to find values of Fi2 and Fi3 that zero W and Z. any help will be very apreciated!
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
double ERF(double Z),ERFC(double A);
float A;
int ACHA_FI_P();
float Fi2,Fi3,FiP[2];
int main()
{
double B,C,D;
while(1)
{
printf("Entre com o valor de A:");
scanf("%f", &A);
printf("A= %f \n",A);
B=ERF(A);
C=ERFC(A);
printf("ERF(A)=%f\n", B);
printf("ERFC(A)=%f\n\n", C);
ACHA_FI_P();
printf("\nValores obtidos para Fi2 e Fi3 sao respectivamente %f e %f.",FiP[0],FiP[1]);
}
return(0);
}
double ERF(double Z)
{
int P;
double a = 0.348;
double b = -0.096;
double c = 0.748;
double d = 0.471;
double y, ERF;
if (Z < 0) { Z = -Z; P = -1;}
else { P = 1; }
y = 1./(1. + (Z * d));
ERF = 1 - ((a * y) + (b * y*y) + (c * y*y*y))*exp(-(Z*Z));
if(P == -1) ERF = -ERF;
return(ERF);
}
double ERFC(double A)
{
double ERFC;
ERFC=(1-ERF(A));
return(ERFC);
}
int ACHA_FI_P ()
{
float dFi,W,Z;
Fi2=0.001;
Fi3=0.001;
dFi=0.001;
while (1)
{
FiP[0]=Fi2;
FiP[1]=Fi3;
W=(exp(-Fi2*Fi2)/ERF(Fi2)-exp(-Fi2*Fi2)/(ERF(Fi3)-ERF(Fi2))-sqrt(3.14));
Z=((exp(-Fi3*Fi3))/(ERF(Fi3)-ERF(Fi2))+(exp(-Fi3*Fi3))/(ERFC(Fi3))-sqrt(3.14));
if((W==0||(W<=0.01 && W>=-0.01))&&((Z==0)||(Z<=0.01 && Z>=-0.01))) {return(0);}
Fi2=Fi2+dFi;
if(Fi2==4){Fi2=0.001; Fi3=Fi3+dFi;}
if(Fi3==4){printf("Nenhum valor encontrado.\n");}
}
}
the error is in the ACHA_FI_P() function... the problem is I couldnt debug this code using dev c++, anybody know a good debugger?
the ACHA_FI_P function is to resolve 2 equations to find values of Fi2 and Fi3 that zero W and Z. any help will be very apreciated!
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
double ERF(double Z),ERFC(double A);
float A;
int ACHA_FI_P();
float Fi2,Fi3,FiP[2];
int main()
{
double B,C,D;
while(1)
{
printf("Entre com o valor de A:");
scanf("%f", &A);
printf("A= %f \n",A);
B=ERF(A);
C=ERFC(A);
printf("ERF(A)=%f\n", B);
printf("ERFC(A)=%f\n\n", C);
ACHA_FI_P();
printf("\nValores obtidos para Fi2 e Fi3 sao respectivamente %f e %f.",FiP[0],FiP[1]);
}
return(0);
}
double ERF(double Z)
{
int P;
double a = 0.348;
double b = -0.096;
double c = 0.748;
double d = 0.471;
double y, ERF;
if (Z < 0) { Z = -Z; P = -1;}
else { P = 1; }
y = 1./(1. + (Z * d));
ERF = 1 - ((a * y) + (b * y*y) + (c * y*y*y))*exp(-(Z*Z));
if(P == -1) ERF = -ERF;
return(ERF);
}
double ERFC(double A)
{
double ERFC;
ERFC=(1-ERF(A));
return(ERFC);
}
int ACHA_FI_P ()
{
float dFi,W,Z;
Fi2=0.001;
Fi3=0.001;
dFi=0.001;
while (1)
{
FiP[0]=Fi2;
FiP[1]=Fi3;
W=(exp(-Fi2*Fi2)/ERF(Fi2)-exp(-Fi2*Fi2)/(ERF(Fi3)-ERF(Fi2))-sqrt(3.14));
Z=((exp(-Fi3*Fi3))/(ERF(Fi3)-ERF(Fi2))+(exp(-Fi3*Fi3))/(ERFC(Fi3))-sqrt(3.14));
if((W==0||(W<=0.01 && W>=-0.01))&&((Z==0)||(Z<=0.01 && Z>=-0.01))) {return(0);}
Fi2=Fi2+dFi;
if(Fi2==4){Fi2=0.001; Fi3=Fi3+dFi;}
if(Fi3==4){printf("Nenhum valor encontrado.\n");}
}
}