运行Octave函数从Shell。

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

Run Octave function form shell

问题

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

  1. A=147;
  2. B=26.3;
  3. C=5.4;
  4. d=0.35*A;
  5. function S=function_test(A,B,C,d)
  6. S=2*A*B*C*d;
  7. end

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

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

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

  1. A=147;
  2. B=26.3;
  3. C=5.4;
  4. d=0.35*A;
  5. function S=function_test(A,B,C,d)
  6. S=2*A*B*C*d;
  7. end

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

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

答案1

得分: 0

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

  1. function_test(1,2,3,4)
  2. ans = 48
  3. res = function_test(1,2,3,4)
  4. res = 48
  5. S = function_test(-1,3,5,7)
  6. S = -210
英文:

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

  1. function_test(1,2,3,4)
  2. ans = 48
  3. res = function_test(1,2,3,4)
  4. res = 48
  5. S = function_test(-1,3,5,7)
  6. 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:

确定