Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 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 ...)
Reply With Quote
  #2  
Old 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.
Reply With Quote
  #3  
Old 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.
Reply With Quote
  #4  
Old 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
Reply With Quote
  #5  
Old 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...
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Solve numerically erf(x) and alternative to scanf"
Thread Thread Starter Forum Replies Last Post
How to solve bottlenecking? Liam Hardware Peripherals 4 25-02-2011 07:35 AM
How to solve code 646? Otilio Operating Systems 5 11-09-2010 04:45 AM
Add scanf without newline Zool Software Development 3 08-10-2009 02:34 PM
How to avoid problems with scanf? Zool Software Development 3 14-05-2009 07:16 PM


All times are GMT +5.5. The time now is 02:55 PM.