Time for action - using the cos function
1. In order to calculate cosine of a number, say π, we simply type:
octave:1>cos(pi) ans = -1
pi is the input argument, cos is the Octave function and -1 is the output from cos. When we use a function we often say that we call that function
2. What if we use a vector as input? Well, why not just try. We know how to instantiate a vector:
octave:2> x = [0:pi/2:2*pi] ans = 0.0000 1.5708 3.1416 4.7124 6.2832
Cosine of x is then:
octave:3>cos(x) ans = 1.0000e+000 6.1230e-017 -1.0000e+000 -1.8369e-016 1.0000e+000
that is, Octave calculates the cosine of each element in the vector.
3. In Command 2, we created a row vector, and the result of Command 3 is therefore also a row vector. If we use a column vector as input to
cos:
octave:4>cos(x') ans = 1.0000e+000 6.1230e-017 -1.0000e+000 -1.8369e-016 1.0000e+000
it returns a column vector.
What just happened?
In Command 1, we use pi
as the input argument to the cos
function. Now, strictly speaking...