Results 1 to 5 of 5

Thread: Solve numerically erf(x) and alternative to scanf

  1. #1
    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. #2
    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. #3
    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. #4
    Join Date
    May 2008
    Posts
    2,297

    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. #5
    henry21r Guest

    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...

Similar Threads

  1. How to solve bottlenecking?
    By Liam in forum Hardware Peripherals
    Replies: 4
    Last Post: 25-02-2011, 07:35 AM
  2. How to solve code 646?
    By Otilio in forum Operating Systems
    Replies: 5
    Last Post: 11-09-2010, 04:45 AM
  3. Add scanf without newline
    By Zool in forum Software Development
    Replies: 3
    Last Post: 08-10-2009, 02:34 PM
  4. How to avoid problems with scanf?
    By Zool in forum Software Development
    Replies: 3
    Last Post: 14-05-2009, 07:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,313,087.44867 seconds with 16 queries