My function in Octave doesn't work

Viewed 8790

I'm working with Octave4.2.1 and I have written this function (in the file OctaveFunction.m):

    function y = squareNumber(x)
      y = x^2;
    endfunction

but if I call the function, I get this error:

error: 'squareNumber' undefined near line 1 column 1

and if I try to call the function in this way:

OctaveFunction squareNumber(4)

I get another error:

warning: function name 'squareNumber' does not agree with function filename 'C:\Users\HOME\Desktop\OctaveFunction.m' error: for x^A, A must be a square matrix. Use .^ for elementwise power. error: called from OctaveFunction at line 2 column 7

Where did I go wrong? Thank you!

2 Answers

You Must rename your file such as your function name for example: your file name is (main.m) and your function name is (main)

Related