Skip to content

This is a new cosine, this will allow you to do things that were almost impossible with Cosine before.πŸ‘½πŸ‘Ύ

License

Notifications You must be signed in to change notification settings

NopAngel/coseno_valioso

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CosenoValioso

CosenoValioso is a custom implementation of the cosine function in C, using the Taylor series expansion. This implementation allows you to calculate the cosine of an angle in degrees with a specified level of accuracy by defining the number of iterations for the Taylor series.

Table of Contents

Introduction

CosenoValioso is an implementation of the cosine function using the Taylor series, which is an infinite sum of terms that are calculated based on the angle. This project is useful for educational purposes, demonstrating how mathematical functions can be approximated using series expansions.

How It Works

The Taylor series expansion of the cosine function is given by:

$$ \cos(x) = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} + \ldots $$

In this implementation, we convert the angle from degrees to radians and then use the series expansion to calculate the cosine. The number of terms (iterations) can be specified to control the accuracy of the result.

Mathematical Background

Taylor Series

The Taylor series is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For a function ( f(x) ), the Taylor series expansion around the point ( x = a ) is given by:

$$ f(x) = f(a) + f'(a)(x - a) + \frac{f''(a)}{2!}(x - a)^2 + \frac{f'''(a)}{3!}(x - a)^3 + \ldots $$

In the case of the cosine function, the Taylor series is centered at ( x = 0 ) (also known as the Maclaurin series), and it only includes even-powered terms because the sine function (the odd terms) is zero at ( x = 0 ).

Cosine Function

The cosine function is a fundamental trigonometric function that describes the relationship between the lengths of the sides of a right triangle and its angles. It is defined for all real numbers and is periodic with a period of ( 2\pi ). The cosine function is even, meaning ( \cos(-x) = \cos(x) ), and has a range of [-1, 1].

The Taylor series expansion of the cosine function is particularly useful because it allows us to approximate the value of ( \cos(x) ) using a finite number of terms, making it possible to compute cosine values even when a calculator or built-in function is not available.

Properties of the Cosine Function

The cosine function has several important properties that make it useful in various applications:

  1. Even Function: The cosine function is symmetric about the y-axis, meaning ( \cos(-x) = \cos(x) ).
  2. Periodic Function: The cosine function repeats its values in regular intervals, with a period of ( 2\pi ). This means ( \cos(x + 2\pi) = \cos(x) ).
  3. Range and Domain: The range of the cosine function is [-1, 1], and its domain is all real numbers.
  4. Maximum and Minimum Values: The cosine function attains its maximum value of 1 at ( x = 2k\pi ) (where ( k ) is an integer) and its minimum value of -1 at ( x = (2k+1)\pi ).

Applications of the Cosine Function

The cosine function has a wide range of applications in various fields, including:

  1. Trigonometry: Used to solve triangles, calculate angles and distances, and in trigonometric identities.
  2. Physics: Describes wave motion, oscillations, and circular motion. It is used in the analysis of alternating current (AC) circuits and sound waves.
  3. Engineering: Used in signal processing, control systems, and mechanical engineering to model periodic phenomena.
  4. Computer Graphics: Used to calculate rotations, lighting effects, and animations in 3D graphics.
  5. Astronomy: Used to model the positions and movements of celestial bodies.

Mathematical Derivations

The Taylor series for the cosine function can be derived using the definition of the Taylor series and the derivatives of the cosine function. The nth derivative of ( \cos(x) ) evaluated at ( x = 0 ) gives the coefficients of the Taylor series:

  1. ( \cos(x) ) at ( x = 0 ) is 1.
  2. The first derivative of ( \cos(x) ) is ( -\sin(x) ), and at ( x = 0 ), it is 0.
  3. The second derivative of ( \cos(x) ) is ( -\cos(x) ), and at ( x = 0 ), it is -1.
  4. The third derivative of ( \cos(x) ) is ( \sin(x) ), and at ( x = 0 ), it is 0.
  5. The fourth derivative of ( \cos(x) ) is ( \cos(x) ), and at ( x = 0 ), it is 1.

This pattern continues, resulting in the Taylor series for ( \cos(x) ):

$$ \cos(x) = \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n}}{(2n)!} $$

Where ( n! ) denotes the factorial of ( n ).

Getting Started

Accuracy

The accuracy of the cosine value depends on the number of iterations specified. More iterations result in a more accurate result but also increase the computation time. For most practical purposes, 10 iterations provide a good balance between accuracy and performance.

Performance

The performance of the program is influenced by the number of iterations used in the Taylor series expansion. Fewer iterations result in faster computations but less accurate results. Conversely, more iterations result in more accurate results but slower computations.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.

Acknowledgments

Thanks to the developers of the GCC compiler.

Thanks to the open-source community for providing valuable resources.

Contact

For any inquiries or feedback, please contact [angelgabrielnieto@outlook.com].

IMPORTANT

Although it may seem useless, this mathematical function is the most useful. In fact, using it correctly can be the key to creating greater things, these are the things that can be taken to the maximum:

Scientific Simulations: Use cosenoValioso in physical and chemical simulations, such as modeling molecules and simulating planetary and stellar motions.

Signal Analysis and Digital Processing: Implement cosenoValioso in digital signal processing (DSP) systems for real-time signal analysis, filtering, and data compression.

Artificial Intelligence and Machine Learning: Include cosenoValioso in machine learning algorithms and neural networks, especially in activation functions and angular data processing.

Control Systems and Robotics: Use cosineValuable in the programming of control systems for robots, such as in the calculation of precise trajectories and motions in advanced robotic systems.

Computer Graphics and Virtual Reality: Apply cosenoValioso in the generation of 3D graphics and virtual reality environments, optimizing the calculation of lights, shadows and object rotations.

Space Technology: Implement cosenoValioso in navigation and control systems for satellites and spacecraft, contributing to the calculation of precise orbits and trajectories.

Cryptography and Information Security: Integrate cosineValue in cryptographic algorithms that require precise calculations with trigon functions.

I have been experimenting for half a week (almost 1 week), and I realized that you can even create Quantum Computers, you just have to know the key of how to use it.

Quantum Computing Cosine Formula

Let's imagine we want to develop a formula that not only calculates the cosine but also incorporates aspects of quantum computing such as qubits and rotation matrices. Here is a hypothetical formula that we could use as a basis for a quantum algorithm:

cos ⁑ q ( π‘₯ )

βˆ‘ 𝑛

0 ∞ ( βˆ’ 1 ) 𝑛 ( π‘ž π‘₯ ) 2 𝑛 ( 2 𝑛 ) ! β‹… π‘ˆ ( πœƒ , πœ™ , πœ† ) Where:

cos ⁑ q ( π‘₯ ) represents the quantum cosine.

π‘ž π‘₯ represents a qubit associated with the angle π‘₯ .

π‘ˆ ( πœƒ , πœ™ , πœ† ) is a quantum rotation matrix acting on the qubit.

In this context, the rotation matrix π‘ˆ ( πœƒ , πœ™ , πœ† ) could be a universal rotation matrix in Hilbert space, defined as:

π‘ˆ ( πœƒ , πœ™ , πœ† )

( cos ⁑ ( πœƒ 2 ) βˆ’ 𝑒 𝑖 πœ† sin ⁑ ( πœƒ 2 ) 𝑒 𝑖 πœ™ sin ⁑ ( πœƒ 2 ) 𝑒 𝑖 ( πœ™ + πœ† ) cos ⁑ ( πœƒ 2 ) ) Where πœƒ , πœ™ and πœ† are parameters that define the rotation in Hilbert space.

Key and Form:

Incorporation of Qubits: Utilize qubits to represent the angle value and other parameters, allowing for the superposition and entanglement of quantum states.

Rotation Matrix: Employ quantum rotation matrices to transform qubit states and compute the cosine efficiently.

Taylor Series: Apply the Taylor series to approximate the value of the quantum cosine, summing successive terms to improve precision.

Implementation in a Quantum Algorithm:

To implement this formula in a quantum algorithm, you would need a quantum simulator or actual quantum hardware such as those provided by IBM Q, Google, or D-Wave. The basic steps would be:

Prepare Qubits: Initialize and prepare the qubits in the desired state.

Apply Quantum Gates: Use quantum gates to apply the necessary rotations and operations.

Measure Qubits: Perform measurements to obtain the final results of the quantum cosine.

Interpret Results: Analyze the results and compare them with classically calculated values to verify accuracy.

Future Potential:

Using quantum computing for advanced trigonometric calculations could revolutionize fields such as:

Simulation of Quantum Systems: Model and simulate complex physical systems with high precision.

Quantum Optimization: Solve combinatorial optimization problems more rapidly than classical computers.

Post-Quantum Cryptography: Develop new cryptographic algorithms resistant to quantum attacks.

LICENSE

MIT License

Copyright (c) 2025 [NopAngel]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

This is a new cosine, this will allow you to do things that were almost impossible with Cosine before.πŸ‘½πŸ‘Ύ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages