Search code examples
functionshelloctave

Run Octave function form shell


It is possible to write a function directly in the octave shell?

A=147;
B=26.3;
C=5.4;
d=0.35*A;

function S=function_test(A,B,C,d)
                                                
S=2*A*B*C*d;

end 

I tried this but if I wanted to know the value of "S", this error appears:

error: 'S' undefined near line 1, column 1

Solution

  • Yes it is possible. You does it correctly. But you missed indicating how you call the function. For me, no error occurs:

    ≫ function_test(1,2,3,4)
    ans = 48
    ≫ res = function_test(1,2,3,4)
    res = 48
    ≫ S = function_test(-1,3,5,7)
    S = -210
    ≫