liveBook · Manning

Sine function

As explained in Julia as a Second Language

sin is Julia's built-in function for computing the sine of an angle or numeric value.

The sine function computes the sine of an angle or numeric value. It connects a right triangle's opposing side with its hypotenuse and helps solve practical angle-and-distance problems, such as locating a ship near a lighthouse. section 3.1

Evaluate sine in the REPL

Julia evaluates sine directly with its built-in function: `sin(3.1415926/2)` produces a value close to `1`. The REPL is useful for testing such expressions interactively. section 2.1

You can also build an approximation with a Taylor series. A loop adds successive terms, and the final accumulated value becomes the function result. With five iterations, a custom implementation produces values very close to Julia's built-in `sin`. section 3.4.1

A practical sine workflow includes:

  • Evaluate a value with `sin(x)` in the Julia REPL. section 2.1
  • Implement an approximation by summing Taylor-series terms in a multiline function. section 3.4.1
  • Increase the iteration limit and compare the approximation with the built-in function. section 3.4.1
Figure 3.1 A captain on a ship could use a sextant to measure angle θ between the horizon and top of a lighthouse.
03-01

Use the sextant-and-lighthouse scene to connect sine with measuring angles and determining distance at sea. section 3.1

How Julia as a Second Language covers it

How deep it goes
Explains the triangle definition and Taylor-series approximation, then implements and compares a finite-loop version without proving the mathematics.
Examples
Demonstrates lighthouse navigation, REPL evaluation, a custom Taylor-series function, and comparisons with built-in `sin`.
What it assumes
Assumes basic Julia expressions, loops, and functions while reviewing right-triangle terminology and mathematical summation from fundamentals.
What you can do after
Apply it via Julia's `sin` function, or build an approximate implementation with loops and Taylor-series terms.
How it connects
Connects sine with cosine, tangent, right triangles, Taylor series, loops, functions, and the Julia REPL.

Also explained in

Compare how 3 books explain sine function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.