Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Error functions using cmath in C++
We are given the variable and the task is to find the probability of the variable using an error function available in C++ STL. This function is available in the cmath header file in C++.
What is an Error function?
Error function in mathematics is also known as Gauss error function which is denoted by erf(). It is a special function that is used in probability, statistic and partial differential equations for the calculation of error that can occur. It is defined as −

There are two closely related error function −
- complementary error function − It is defined as erfc x = 1 - erf x
- imaginary error function − It is defined aserfi x = -ierf(ix), where i is the imaginary unit
Example
Input
i = 2.25
Output
erf(i) i.e. 0.998537
Input
i = 1.25
Output
erf(i) i.e. 0.9229
Example
#include <iostream>
#include <cmath>
using namespace std;
double probab(double i){
double probab_1 = erf(i);
return probab_1;
}
int main (){
double i = 2.25;
cout<<"Probability is :"<<probab(i)<< endl;
return 0;
}
Output
Probability is : 0.998537
Example
#include <iostream>
#include <cmath>
using namespace std;
double probab(double i){
double probab_1 = erf(i);
return probab_1;
}
int main (){
double i = 1.25;
cout<<"Probability is :"<<probab(i)<< endl;
return 0;
}
Output
Probability is : 0.9229
Advertisements