How to use a vector function in Matlab and Octave
The parameter of a function can also be a vector in Matlab / Octave
Example
Define a vector
>> x = [0, pi/6, pi/4, pi/3, pi/2]
The term pi is the default constant π
Calculate the sine function using the vector x as a parameter
>> sin(x)
The function computes the sine function for each element of vector x and outputs another vector
ans =
0.00000 0.50000 0.70711 0.86603 1.00000
This command is the same as writing the sine function five times
>> sin(0)
ans = 0
>> sin(pi/6)
ans = 0.50000
>> sin(pi/4)
ans = 0.70711
>> sin(pi/3)
ans = 0.86603
>> sin(pi/2)
ans = 1
https://how.okpedia.org/en/matlab/how-to-use-a-vector-function-in-matlab-and-octave
Report an error or share a suggestion to enhance this page