TechArena Community Solve numerically erf(x) and alternative to scanf
 User Name Remember Me? Password

#1
23-10-2009
 Member Join Date: Jan 2009 Posts: 638
Solve numerically erf(x) and alternative to scanf

Looking to numerically solve the function erf (x). I searched the internet, I find resolutions, like that proposed by wikipedia http://en.wikipedia.org/wiki/Error_function

But what I would like to have is a way to make a resolution without using these solutions, probably one can use the algorithm Horner, but I do not see how. an idea?

Basically I want an algorithm to solve this integral, without going through already existing solutions.

Otherwise I also seek an alternative to scanf to read the value the user enters. I want to detect for example if it returns a character in place of a value to exit the program. To give something like that,

Code:
```#include <stdio.h>
int main()
{
float erf;
float x;
do
{
printf("enter a value for x, or q if you want to quit\n" );
scanf ("%f",&x);                             //scanf does not seem very appropriate for what I do (detect "q" to quit)
erf=x;                                          //was replaced by an algorithm allowing me to get erf, I am still looking
printf("erf=%f\n",erf);
}
while ()  ; //condition in a while ... if I can detect when a user enters q...
return 0;
}```
The code here is not of great importance, it's just to give a general idea. What I need is an alternative to scanf, and a way to solve erf (horner algorithm, trapezoidal method ...)
#2
23-10-2009
 Member Join Date: May 2008 Posts: 685
Re: Solve numerically erf(x) and alternative to scanf

For the alternative to scanf(): fgets() + a conversion function whatsoever (strtod (), strtol (), etc.)

There is a function erf () in C99 (not C90), declared in <math.h>. From memory, it corresponds to use older at least on Unix.

At worst, you can search through the implementation of a BSD lib, the license should not be a problem to you.
#3
23-10-2009
 Member Join Date: Jan 2009 Posts: 638
Re: Solve numerically erf(x) and alternative to scanf

The problem is that I can not use an existing function of erf (), I have to program an algorithm to determine the values of erf and the associated error. But I can use an existing algorithm, if I know the source.
#4
24-10-2009
 Member Join Date: May 2008 Posts: 2,293
Re: Solve numerically erf(x) and alternative to scanf

What bothers you from using one of the approximations given in wikipedia. In addition, it is expressly for those who code in C or Fortran (as said in it). Otherwise, well you seek an algorithm for computing integral (method of rectangles, trapezoids ...) http://en.wikipedia.org/wiki/Numerical_integration
#5
26-10-2009
 henry21r Posts: n/a
Re: Solve numerically erf(x) and alternative to scanf

change the datatype of erf to void then it can help i think.. else see C++ help file.... and use according to syntax...

 Tags: