📜  最大化给定半径的半圆的值

📅  最后修改于: 2021-05-04 10:22:01             🧑  作者: Mango

我们给了一个半径为R半圆我们可以将圆周上的任意点设为P。现在,从该点P到直径的两侧画两条线。设线为PQPS

任务是找到给定R的表达式PS 2 + PQ的最大值

半圆

例子 :

Input : R = 1 
Output : 4.25  
(4*1^2 + 0.25) = 4.25

Input : R = 2
Output : 16.25 
(4 * 2^2 + 0.25)= 16.25

令F = PS ^ 2 + PQ。我们知道QS = 2R(半圆直径)
->我们也知道,三角形PQS总是成直角三角形,而不管圆上圆周上P点的位置如何

1.)QS^2 = PQ^2 + PS^2 (Pythagorean Theorem)

2.) Adding and Subtracting PQ on the RHS
     QS^2 = PQ^2 + PS^2 + PQ - PQ

3.) Since QS = 2R
   4*R^2 + PQ - PQ^2 = PS^2 + PQ 
=> 4*R^2 + PQ - PQ^2 = F

4.) Using the concept of maxima and minima 
differentiating F with respect to PQ and equating 
it to 0 to get the point of maxima for F i.e.
   1 - 2 * PQ = 0
 => PQ = 0.5

5.) Now F will be maximum at F = 4*R^2 + 0.25 
C++
// C++ program to find 
// the maximum value of F
#include 
using namespace std;
  
// Function to find the 
// maximum value of F
double maximumValueOfF (int R)
{
    // using the formula derived for 
    // getting the maximum value of F
    return 4 * R * R + 0.25;     
}
      
// Drivers code
int main() 
{
    int R = 3; 
    printf("%.2f", maximumValueOfF(R)); 
    return 0;
}


JAVA
// JAVA program to find 
// the maximum value of F
import java.io.*;
  
class GFG
{
      
    // Function to find the 
    // maximum value of F
    static double maximumValueOfF (int R)
    {
          
        // using the formula derived for 
        // getting the maximum value of F
        return 4 * R * R + 0.25;     
    }
      
    // Driver code
    public static void main (String[] args)
    {
        int R = 3; 
        System.out.println(maximumValueOfF(R)); 
    }
          
}
  
// This code is contributed 
// by anuj_67.


Python3
# python program to find 
# the maximum value of F
  
# Function to find the 
# maximum value of F
def maximumValueOfF (R):
      
    # using the formula derived for 
    # getting the maximum value of F
    return 4 * R * R + 0.25
  
       
# Drivers code
R = 3
print(maximumValueOfF(R))
  
# This code is contributed by Sam007.


C#
// C# program to find the 
// maximum value of F
using System;
  
class GFG 
{
      
    // Function to find the 
    // maximum value of F
    static double maximumValueOfF (int R)
    {
          
        // using the formula derived for 
        // getting the maximum value of F
        return 4 * R * R + 0.25;     
    }
      
    // Driver code
    public static void Main ()
    {
        int R = 3; 
        Console.WriteLine(maximumValueOfF(R)); 
    }
          
}
  
// This code is contributed by Sam007.


PHP


输出 :
36.25