
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Arcsine of a Given Value in Haskell
This tutorial will help us in finding the arcsine of the given value. The arcsine is the inverse function of the sine. It takes the output value of the sine function, and returns the input angle that would produce that output value.
The arcsine function is useful in trigonometry and geometry in finding missing angles and sides in right-angled triangles.
Syntax
asin(angle)
Here, asin() is a built-in function and value is passed as parameter to compute the arcsine of the value passed. The arcsine function maps a value between -1 and 1 to an angle between -?/2 and ?/2 radians.
Method 1: Finding arcsine using in-built asin() function
In this method, asin is defined as an alias for atan (x / sqrt (1 - x^2)), which is the standard mathematical definition of the arcsine.
Algorithm
Step 1 ? Program execution will be started from main function. The main() function has whole control of the program.
Step 2 ? A variable named, "angle" is being initialized. Initially, it will have the garbage value. Then, a constant value is being assigned to it.
Step 3 ? The constant value must be between -1 and 1 inclusive, otherwise the asin() will give the value NaN. This value is assigned to the variable "angle" by using the assignment operator.
Step 4 ? The inbuilt arcsine function, asin() is called. It's definition is already available in the standard library
Step 5 ? "angle" variable that contains the value is passed as parameter to the asin() function.
Step 6 ? The result is assigned to the "result" variable after asin() function computes the final resultant value and final output is displayed by printing the result value.
Example
In this example, we are going to see that how we can find the arcsine of the value passed. This can be done by using in-built asin() function. In
main = do let angle = 0.5 putStrLn "The value between -1 and 1, whose arcsine is to be computed is: " print (angle) let result=asin(angle) putStrLn "The resultant arcsine value is: " print (result)
Output
The value between -1 and 1, whose arcsine is to be computed is: 0.5 The resultant arcsine value is: 0.5235987755982989
Method 2: Using in-built asin() function for complex numbers
In this method, the asin function from ?Data.Complex' module is used to find the arcsine of a complex number y, where y is the complex number with only the real part as x and the imaginary part as 0. The output of asin is a complex number, where the imaginary part of that complex number is the arcsine of the given value.
Algorithm
Step 1 ? A "Data.Complex" module is imported to work over complex numbers.
Step 2 ? Program execution will be started from main function. The main() function has whole control of the program.
Step 3 ? A variable named "x" that contains the real part of the complex number , is being initialized. And a value between -1 and 1 inclusive is assigned to it.
Step 4 ? A variable named "y" contains the whole complex number including the real and imaginary part, the real part value is taken from the "x" variable and imaginary part is taken as 0.
Step 5 ? The inbuilt arcsine function, asin() is called. It's definition is already available in the standard library.
Step 6 ? "y" variable that contains the complex number , is passed as parameter to the asin() function.
Step 7 ? The result is assigned to the "z" variable after asin() function computes the final resultant value and final output is displayed by printing the imaginary part of "z" variable.
Example
In this program, the asin function from ?Data.Complex' module is used to find the arcsine of a complex number
import Data.Complex main :: IO () main = do let x = -0.3 let y = x :+ 0 let z = asin y putStr "The arcsine of the value is: " print (imagPart z)
Output
The arcsine of the value is: -0.0
Conclusion
The arcsine value for the given value in Haskell can be calculated by using the asin() function. The value passed as parameter to this function must be between -1 and 1 inclusive.
For the arcsine of complex numbers, the output of asin is a complex number where the imaginary part of that complex number is the arcsine of the given value. This is only for real values, for complex values the arcsine is not defined.