Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

Error Functions ใช้ cmath ใน C++

เราได้รับตัวแปรและงานคือหาความน่าจะเป็นของตัวแปรโดยใช้ error function ที่มีอยู่ใน C++ STL ฟังก์ชันนี้มีอยู่ในไฟล์หัวข้อ cmath ใน C++

Error Function คืออะไร?

Error function ในคณิตศาสตร์รู้จักในชื่อ Gauss error function ซึ่งแทนด้วย erf() เป็นฟังก์ชันพิเศษที่ใช้ในความน่าจะเป็น สถิติ และสมการอนุพันธ์บางส่วนสำหรับการคำนวณข้อผิดพลาดที่อาจเกิดขึ้น ถูกกำหนดว่า:

Error Functions ใช้ cmath ใน C++

มี error function ที่เกี่ยวข้องใกล้ชิดสองตัว:

  • complementary error function - ถูกกำหนดว่า erfc x = 1 - erf x
  • imaginary error function - ถูกกำหนดว่า erfi x = -ierf(ix) โดยที่ i คือหน่วยจินตภาพ

ตัวอย่าง

Input

i = 2.25

Output

erf(i) i.e. 0.998537

Input

i = 1.25

Output

erf(i) i.e. 0.9229

ตัวอย่าง

#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;
}

ผลลัพธ์

Probability is : 0.998537

ตัวอย่าง

#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;
}

ผลลัพธ์

Probability is : 0.9229