Program to determine focal length of a spherical mirror
Write a program to determine the focal length of a spherical mirror.
Focal length is the distance between the center of the mirror to the principal foci
In order to determine the focal length of a spherical mirror, we should know the radius of curvature of that mirror. The distance from the vertex to the center of curvature is called the radius of curvature
The focal length is half the radius of curvature
Formula :
F = ( R / 2 ) for concave mirror
F = – ( R / 2 ) for convex mirror
Examples:
For a concave mirror
Input: R = 30
Output: F = 15
For a convex mirror
Input: R = 25
Output: F = – 12.5
Approach: To solve the problem follow the below idea:
Use the formula given above to calculate the focal length of a concave/convex spherical mirror
C++
#include <bits/stdc++.h>
using namespace std;
float focal_length_concave( float R) { return R / 2; }
float focal_length_convex( float R) { return -(R / 2); }
int main()
{
float R = 30;
cout << "Focal length of spherical"
<< "concave mirror is : "
<< focal_length_concave(R) << " units\n" ;
cout << "Focal length of spherical"
<< "convex mirror is : " << focal_length_convex(R)
<< " units" ;
return 0;
}
|
Java
import java.lang.*;
import java.util.*;
public class GfG {
public static float focal_length_concave( float R)
{
return R / 2 ;
}
public static float focal_length_convex( float R)
{
return -(R / 2 );
}
public static void main(String argc[])
{
float R = 30 ;
System.out.print( "Focal length of"
+ "spherical concave"
+ "mirror is : "
+ focal_length_concave(R)
+ " units\n" );
System.out.println( "Focal length of"
+ "spherical convex"
+ "mirror is : "
+ focal_length_convex(R)
+ " units" );
}
}
|
Python
def focal_length_concave(R):
return R / 2
def focal_length_convex(R):
return - (R / 2 )
if __name__ = = "__main__" :
R = 30
print ( "Focal length of spherical concave mirror is :" ,
focal_length_concave(R), " units" )
print ( "Focal length of spherical convex mirror is : " ,
focal_length_convex(R), " units" )
|
C#
using System;
class GfG {
public static float focal_length_concave( float R)
{
return R / 2;
}
public static float focal_length_convex( float R)
{
return -(R / 2);
}
public static void Main(String[] argc)
{
float R = 30;
Console.Write( "Focal length of"
+ "spherical concave"
+ "mirror is : "
+ focal_length_concave(R)
+ " units\n" );
Console.Write( "Focal length of"
+ "spherical convex"
+ "mirror is : "
+ focal_length_convex(R) + " units" );
}
}
|
PHP
<?php
function focal_length_concave( $R )
{
return $R / 2 ;
}
function focal_length_convex( $R )
{
return - ( $R / 2 ) ;
}
$R = 30 ;
echo "Focal length of spherical" ,
"concave mirror is : " ,
focal_length_concave( $R ),
" units\n" ;
echo "Focal length of spherical" ,
" convex mirror is : " ,
focal_length_convex( $R ),
" units" ;
?>
|
Javascript
<script>
function focal_length_concave(R)
{
return R / 2 ;
}
function focal_length_convex(R)
{
return - ( R / 2 ) ;
}
let R = 30 ;
document.write( "Focal length of" +
"spherical concave" +
"mirror is : " +
focal_length_concave(R) +
" units" + "<br/>" );
document.write( "Focal length of" +
"spherical convex" +
"mirror is : " +
focal_length_convex(R) +
" units" );
</script>
|
Output
Focal length of sphericalconcave mirror is : 15 units
Focal length of sphericalconvex mirror is : -15 units
Time complexity: O(1) because constant operations are performed.
Auxiliary space: O(1), as constant operations are being performed.
Last Updated :
20 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...