📜  求双曲线偏心率的程序

📅  最后修改于: 2021-10-23 09:02:16             🧑  作者: Mango

给定两个整数AB ,代表方程(X 2 / A 2 ) – (Y 2 / B 2 ) = 1的双曲线的半长轴和半短轴的长度,任务是计算给定双曲线的偏心率。

例子:

方法:给定的问题可以通过使用公式来解决椭圆的偏心率。

  • 半长轴的长度是A
  • 半短轴的长度是B
  • 因此,椭圆的偏心率由下式给出\sqrt(1 + \frac{B^2}{A^2})          其中 A > B

因此,想法是打印的值\sqrt(1 + \frac{B^2}{A^2})          作为椭圆的偏心率。

下面是上述方法的实现:

C++
// C++ program for the above approach
 
#include 
using namespace std;
 
// Function to find the eccentricity
// of a hyperbola
double eccHyperbola(double A, double B)
{
    // Stores the squared ratio
    // of major axis to minor axis
    double r = (double)B * B / A * A;
 
    // Increment r by 1
    r += 1;
 
    // Return the square root of r
    return sqrt(r);
}
 
// Driver Code
int main()
{
    double A = 3.0, B = 2.0;
    cout << eccHyperbola(A, B);
 
    return 0;
}


Java
// Java program for the above approach
import java.util.*;
 
class GFG{
 
// Function to find the eccentricity
// of a hyperbola
static double eccHyperbola(double A, double B)
{
     
    // Stores the squared ratio
    // of major axis to minor axis
    double r = (double)B * B / A * A;
 
    // Increment r by 1
    r += 1;
 
    // Return the square root of r
    return Math.sqrt(r);
}
 
// Driver Code
public static void main(String[] args)
{
    double A = 3.0, B = 2.0;
     
    System.out.print(eccHyperbola(A, B));
}
}
 
// This code is contributed by Amit Katiyar


Python3
# Python3 program for the above approach
import math
 
# Function to find the eccentricity
# of a hyperbola
 
 
def eccHyperbola(A, B):
 
    # Stores the squared ratio
    # of major axis to minor axis
    r = B * B / A * A
 
    # Increment r by 1
    r += 1
 
    # Return the square root of r
    return math.sqrt(r)
 
 
# Driver Code
if __name__ == "__main__":
 
    A = 3.0
    B = 2.0
    print(eccHyperbola(A, B))
 
    # This code is contributed by ukasp


C#
// C# program for the above approach
using System;
 
class GFG{
 
// Function to find the eccentricity
// of a hyperbola
static double eccHyperbola(double A, double B)
{
     
    // Stores the squared ratio
    // of major axis to minor axis
    double r = (double)B * B / A * A;
 
    // Increment r by 1
    r += 1;
 
    // Return the square root of r
    return Math.Sqrt(r);
}
 
// Driver Code
public static void Main(String[] args)
{
    double A = 3.0, B = 2.0;
     
    Console.Write(eccHyperbola(A, B));
}
}
 
// This code is contributed by Princi Singh


Javascript


输出:
2.23607

时间复杂度: O(1)
辅助空间: O(1)

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程