八度函数调用中未定义的arg(是的' sa脚本文件)

发布于 2025-01-25 00:34:57 字数 782 浏览 1 评论 0原文

请回答

eulerballistic(motion, [0;100;0;-9.8;0], 10)
needs to be
eulerballistic(@motion, [0;100;0;-9.8;0], 10)
               ^     

当我将这两个功能复制并粘贴到CLI中时, ,我会得到“错误:v Undefined” 当我发出“运行proj3b.m”时,同样的问题 我知道脚本文件和功能文件之间的区别。 当我正确地将proj3b.m放入函数文件时,我会遇到相同的错误。

使用八度6.4.0

proj3b.m

1+1;
function z = motion(t, v)
  x2 = 0;
  y2 = -9.8;
  z = v + [v(3); v(4); x2; y2; 1]*t;
  return
endfunction

eulerballistic(motion, [0;100;0;-9.8;0], 10)

eulerballistic.m

function z = eulerballistic(f, z0, deltat)
z = z0;
i = 1;
while z(2,i) > 0
   zprime = f(z(5,i), z(:,i))
   z(:,i+1) = z(:,i) + deltat*zprime;
   
   i = i + 1;
   if i > 100
       break;
   end
end
z = z(:, 1:end-1);
end

ANSWER

eulerballistic(motion, [0;100;0;-9.8;0], 10)
needs to be
eulerballistic(@motion, [0;100;0;-9.8;0], 10)
               ^     

When I copy and paste these two functions into the cli, I get "error: v undefined"
When I issue "run proj3b.m", same problem
I know about the difference between a script file and a function file.
When I make proj3b.m into a function file properly, I get the same error.

Using octave 6.4.0

proj3b.m

1+1;
function z = motion(t, v)
  x2 = 0;
  y2 = -9.8;
  z = v + [v(3); v(4); x2; y2; 1]*t;
  return
endfunction

eulerballistic(motion, [0;100;0;-9.8;0], 10)

eulerballistic.m

function z = eulerballistic(f, z0, deltat)
z = z0;
i = 1;
while z(2,i) > 0
   zprime = f(z(5,i), z(:,i))
   z(:,i+1) = z(:,i) + deltat*zprime;
   
   i = i + 1;
   if i > 100
       break;
   end
end
z = z(:, 1:end-1);
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚你心 2025-02-01 00:34:57

呼叫仪需要在功能名称前的限制符 @。

The callsite needs the qualifier @ in front of the function name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文