Find the Area of the Largest Rectangle That Can Be Inscribed in the Ellipse X2 A2 + Y2 B2 = 1
Surface area of Largest rectangle that tin can be inscribed in an Ellipse
Given an ellipse, with major axis length 2a & 2b. The task is to find the area of the largest rectangle that can exist inscribed in information technology.
Examples:
Input: a = 4, b = three Output: 24 Input: a = 10, b = viii Output: 160
Approach:
Let the upper right corner of the rectangle has co-ordinates (x, y),
And then the area of rectangle, A = iv*x*y.
Now,
Equation of ellipse, (x2/atwo) + (y2/b2) = 1
Thinking of the area as a office of x, we have
dA/dx = 4xdy/dx + 4y
Differentiating equation of ellipse with respect to x, we have
2x/aii + (2y/b2)dy/dx = 0,
so,
dy/dx = -bii10/a2y,
and
dAdx = 4y – (4b2x2/a2y)
Setting this to 0 and simplifying, nosotros have y2 = biix2/a2 .
From equation of ellipse nosotros know that,
y2=btwo – b2ten2/a2
Thus, y2=b2 – yii , 2y2=b2 , and y2btwo = ane/ii.
Clearly, and then, 102a2 = 1/ii also, and the expanse is maximized when
ten= a/√2 and y=b/√2
And then the maximum expanse Expanse, Amax = 2ab
Beneath is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using
namespace
std;
bladder
rectanglearea(
bladder
a,
float
b)
{
if
(a < 0 || b < 0)
return
-1;
return
2 * a * b;
}
int
master()
{
float
a = 10, b = eight;
cout << rectanglearea(a, b) << endl;
return
0;
}
Java
import
java.util.*;
import
java.lang.*;
import
java.io.*;
class
GFG{
static
float
rectanglearea(
float
a,
float
b)
{
if
(a <
0
|| b <
0
)
return
-
ane
;
return
ii
* a * b;
}
public
static
void
chief(String args[])
{
float
a =
10
, b =
8
;
System.out.println(rectanglearea(a, b));
}
}
Python 3
def
rectanglearea(a, b) :
if
a <
0
or
b <
0
:
return
-
i
return
2
*
a
*
b
if
__name__
=
=
"__main__"
:
a, b
=
10
,
8
print
(rectanglearea(a, b))
C#
using
System;
class
GFG
{
static
float
rectanglearea(
bladder
a,
bladder
b)
{
if
(a < 0 || b < 0)
render
-1;
render
2 * a * b;
}
public
static
void
Main()
{
float
a = x, b = 8;
Panel.WriteLine(rectanglearea(a, b));
}
}
PHP
<?php
role
rectanglearea(
$a
,
$b
)
{
if
(
$a
< 0
or
$b
< 0)
return
-one;
return
2 *
$a
*
$b
;
}
$a
= 10;
$b
= viii;
echo
rectanglearea(
$a
,
$b
);
?>
Javascript
<script>
function
rectanglearea(a , b)
{
if
(a < 0 || b < 0)
return
-ane;
render
2 * a * b;
}
var
a = ten, b = eight;
document.write(rectanglearea(a, b));
</script>
Attending reader! Don't stop learning at present. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To consummate your training from learning a language to DS Algo and many more than, please refer Consummate Interview Preparation Course .
Source: https://www.geeksforgeeks.org/area-of-largest-rectangle-that-can-be-inscribed-in-an-ellipse/
Post a Comment for "Find the Area of the Largest Rectangle That Can Be Inscribed in the Ellipse X2 A2 + Y2 B2 = 1"