ฟังก์ชัน beta(), betaf() และ betal() เป็นฟังก์ชันในตัว (built-in) ใน Standard Template Library (STL) ของ C++ ฟังก์ชันเหล่านี้ใช้คำนวณฟังก์ชัน beta ของจำนวนจริงบวกสองจำนวน
สูตรฟังก์ชัน Beta:
$B(x,y)=\int_{0}^{1}t^{(x-1)}(1-t)^{(y-1)}dt$
beta()
ฟังก์ชัน beta() ใช้กับชนิดข้อมูล double รับพารามิเตอร์แบบ double และคืนค่าเป็น double
Syntax
double beta(double x, double y)
Parameters
x - ค่า double สำหรับ x ในฟังก์ชัน beta y - ค่า double สำหรับ y ในฟังก์ชัน beta
คืนค่า double ผลลัพธ์ของฟังก์ชัน beta
ตัวอย่าง
#include <bits/stdc++.h>
using namespace std;
int main() {
double x = 4.93;
double y = 5.01;
double result = beta(x, y);
cout << "B(" << x << " , " << y << ") = " << result << "\n";
return 0;
}
ผลลัพธ์
B(4.93 , 5.01) = 0.00166054
betaf()
ฟังก์ชัน betaf() ใช้กับชนิดข้อมูล float รับพารามิเตอร์แบบ float และคืนค่าเป็น float
Syntax
float betaf(float x, float y)
Parameters
x - ค่า float สำหรับ x ในฟังก์ชัน beta y - ค่า float สำหรับ y ในฟังก์ชัน beta
คืนค่า float ผลลัพธ์ของฟังก์ชัน beta
ตัวอย่าง
#include <bits/stdc++.h>
using namespace std;
int main() {
float x = 0.31;
float y = 3.99;
float result = betaf(x, y);
cout << "B(" << x << " , " << y << ") = " << result << "\n";
return 0;
}
ผลลัพธ์
B(0.31 , 3.99) = 1.93395
betal()
ฟังก์ชัน betal() ใช้กับชนิดข้อมูล long double รับพารามิเตอร์แบบ long double และคืนค่าเป็น long double
Syntax
long double betal(long double x, long double y)
Parameters
x - ค่า long double สำหรับ x ในฟังก์ชัน beta y - ค่า long double สำหรับ y ในฟังก์ชัน beta
คืนค่า long double ผลลัพธ์ของฟังก์ชัน beta
ตัวอย่าง
#include <bits/stdc++.h>
using namespace std;
int main() {
long double x = 3453.35451;
long double y = 9862.89651;
long double result = betal(x, y); // แก้จาก betaf เป็น betal
cout << "B(" << x << " , " << y << ") = " << result << "\n";
return 0;
}
ผลลัพธ์
B(3453.35 , 9862.9) = 4.39947e-3312