📜  谐波进行

📅  最后修改于: 2021-04-27 17:30:39             🧑  作者: Mango

如果项的倒数在AP中,则数字序列称为和声级数。简而言之,如果1 / a,1 / b,1 / c,1 / d,1 / e,1 / f在AP中,则a,b,c,d,e,f在HP中。例如,1 / a,1 /(a + d),1 /(a + 2d)等位于HP中,因为a,a + d,a + 2d位于AP中。

关于谐波发展的事实:

  1. 为了解决调和级数问题,应制作相应的AP系列,然后再解决该问题。
  2. 由于AP的n项由an = a +(n-1)d给出,因此HP的n项由1 / [a +(n -1)d]给出
  3. 对于两个数,如果A,G和H分别是算术,几何和调和平均值,则
    • A≥G≥H
    • AH = G 2 ,即A,G,H在GP中
  4. 如果我们需要在HP中找到三个数字,则应将其假定为1 / a–d,1 / a,1 / a + d
  5. 通过首先将它们转换为AP可以解决HP的大多数问题

谐波渐进公式:

我们如何检查一个系列是否为谐波级数?
这个想法是使给定的数组或序列倒数。倒数后,检查连续元素之间的差异是否相同。如果所有差异都相同,则可以进行算术级数运算。因此,我们知道这些项的倒数是否在AP中,那么给定一系列序列在HP中。让我们以1 / 5、1 / 10、1 / 15、1 / 20、1 / 25为序列,并检查是否为谐波的进展与否。下面是实现:

C++
// CPP program to check if a given  
// array can form harmonic progression 
#include
using namespace std;
  
bool checkIsHP(vector &arr)
{
    int n = arr.size();
  
    if (n == 1)
    {
        return true;
    }
  
    // Find reciprocal of arr[]  
    vector rec;
    for (int i = 0; i < n; i++)
    {
        rec.push_back((1 / arr[i]));
    }
  
    // return (rec);  
  
    // After finding reciprocal, check if  
    // the reciprocal is in A. P.  
    // To check for A.P., first Sort the  
    // reciprocal array, then check difference  
    // between consecutive elements  
    sort(rec.begin(), rec.end());
    int d = (rec[1]) - (rec[0]);
    for (int i = 2; i < n; i++)
    {
        if (rec[i] - rec[i - 1] != d)
        {
            return false;
        }
    }
  
    return true;
}
  
// Driver Code
int main()
{
    // series to check whether it is in H.P  
    vector arr = {1 / 5, 1 / 10, 1 / 15, 1 / 20, 1 / 25};
  
    // Checking a series is in H.P or not  
    if (checkIsHP(arr))
    {
        cout << "Yes" << std::endl;
    }
    else
    {
        cout << "No" <


Java
// Java program to check if a given 
// array can form harmonic progression
import java.util.*;
  
class GFG
{
static boolean checkIsHP(double []arr) 
{
    int n = arr.length; 
      
    if (n == 1) 
        return true;
  
    // Find reciprocal of arr[] 
    ArrayList rec = new ArrayList(); 
    for (int i = 0; i < n; i++)
        rec.add((int)(1 / arr[i]));
      
    // return (rec); 
  
    // After finding reciprocal, check if 
    // the reciprocal is in A. P. 
    // To check for A.P., first Sort the 
    // reciprocal array, then check difference 
    // between consecutive elements 
    Collections.sort(rec);
    int d = (int)rec.get(1) - (int)rec.get(0); 
    for (int i = 2; i < n; i++) 
        if (rec.get(i) - rec.get(i - 1) != d) 
            return false;
  
    return true;
}
  
// Driver code 
public static void main(String[] args)
{
    // series to check whether it is in H.P 
    double arr[] = { 1/5, 1/10, 1/15,
                          1/20, 1/25 }; 
      
    // Checking a series is in H.P or not 
    if (checkIsHP(arr)) 
        System.out.println("Yes"); 
    else
        System.out.println("No"); 
}
}
  
// This code is contributed by mits


Python3
# Python3 program to check if a given 
# array can form harmonic progression
  
def checkIsHP(arr):
  
    n = len(arr)
      
    if (n == 1): 
        return True
  
    # Find reciprocal of arr[]
    rec = []
    for i in range(0, len(arr)):
        a = 1 / arr[i]
        rec.append(a)
    return(rec)
  
    # After finding reciprocal, check if the
    # reciprocal is in A. P.
    # To check for A.P., first Sort the 
    # reciprocal array, then check difference
    # between consecutive elements
    rec.sort()
    d = rec[1] - rec[0]
    for i in range(2, n):
        if (rec[i] - rec[i-1] != d):
            return False
  
    return True
  
# Driver code
if __name__=='__main__':
      
    # series to check whether it is in H.P
    arr = [ 1/5, 1/10, 1/15, 1/20, 1/25 ]    
      
    # Checking a series is in H.P or not
    if (checkIsHP(arr)):
        print("Yes")
    else: 
        print("No")


C#
// C# program to check if a given 
// array can form harmonic progression
using System;
using System.Collections;
class GFG
{
static bool checkIsHP(double[] arr) 
{
    int n = arr.Length; 
      
    if (n == 1) 
        return true;
  
    // Find reciprocal of arr[] 
    ArrayList rec = new ArrayList(); 
    for (int i = 0; i < n; i++)
        rec.Add((int)(1 / arr[i]));
      
    // return (rec); 
  
    // After finding reciprocal, check if 
    // the reciprocal is in A. P. 
    // To check for A.P., first Sort the 
    // reciprocal array, then check difference 
    // between consecutive elements 
    rec.Sort();
    int d = (int)rec[1] - (int)rec[0]; 
    for (int i = 2; i < n; i++) 
        if ((int)rec[i] - (int)rec[i - 1] != d) 
            return false;
  
    return true;
}
  
// Driver code 
public static void Main()
{
    // series to check whether it is in H.P 
    double[] arr = { 1/5, 1/10, 1/15,
                        1/20, 1/25 }; 
      
    // Checking a series is in H.P or not 
    if (checkIsHP(arr)) 
        Console.WriteLine("Yes"); 
    else
        Console.WriteLine("No"); 
}
}
  
// This code is contributed by mits


PHP


输出:

Yes

时间复杂度: O(n Log n)。

与谐波进行有关的基本程序

  • 谐波级数总和
  • 查找第N个谐波数的程序
  • 级数之和(n / 1)+(n / 2)+(n / 3)+(n / 4)+……。+(n / n)
  • 检查给定编号是否为矿石编号
  • 直至成功的预期试验次数

最近有关谐波进行的文章!