运行Octave函数从Shell。

huangapple go评论55阅读模式
英文:

Run Octave function form shell

问题

在Octave终端中直接编写一个函数是可能的吗?

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 

我尝试了这个,但如果我想知道"S"的值,会出现以下错误:

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

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

答案1

得分: 0

是的,这是可能的。你做得没错。但是你漏掉了如何调用函数的说明。对我来说,没有错误发生:

≫ 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
英文:

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
≫ 

huangapple
  • 本文由 发表于 2023年2月7日 00:38:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364127.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定