lettura simple

Sine Function in Scilab

In Scilab, the trigonometric sine of an angle is effortlessly computed using the sin() function.

sin(x)

Here, the angle should be specified in radians within the parentheses.

The sin() function then yields the sine value for the provided angle.

It's worth noting that Scilab's `sin()` is among its suite of integral trigonometric functions. This versatile function accepts either a singular value or an array. When an array is provided, the function diligently computes the sine for each constituent element, producing a corresponding array of results.

For clarity, consider the following example.

To assign the angle of π/4 radians (equivalent to 45°) to the variable x, simply use:

x = %pi / 4

In Scilab's lexicon, %pi stands for the mathematical constant pi, approximately valued at 3.14.

Subsequently, to compute the sine, invoke the sin() function.

sin(x)

For the angle π/4 radians (45°), the sine value is approximately 0.7071.

0.7071068

Moreover, the sin() function is adept at handling arrays

Create an array of values assigned to x

x = [0, %pi / 2, %pi, 3 * %pi / 2];

This array, whether a vector or matrix, contains angles, each measured in radians.

To compute the sine values for this array.

sin(x)

The function processes each array element, resulting in:

[0, 1, 0, -1]

But what if your angle is in degrees?

While the sin() function inherently expects angles in radians, angles in degrees can be seamlessly converted using:

$$ \text{radianti} = \text{gradi} \cdot \frac{\pi}{180} $$

Computing the sine for 45°.

x = 45 * %pi / 180

Poi calcola il seno di 45° usando la funzione sin()

sin(x)

Yields an approximate value of 0.7071

0.7071068

This approach ensures accurate sine computations for angles in either measurement.

To culminate, if you're inclined to visualize the sine function, employ the following command sequence:

  1. x = linspace(0, 2, 1000);
  2. y = sin(x * %pi);
  3. plot(x, y);
  4. xlabel('x (radiant)');
  5. ylabel('cos(x)');
  6. title('Sine');

Executing this script will elegantly plot the sine curve spanning from 0 to 2π radians.

Visualizing the sine curve remains a pivotal feature in Scilab.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin