在 Mathematica 中的给定点评估系统

发布于 2024-12-15 00:45:41 字数 380 浏览 1 评论 0原文

f1[x_, y_] := x^2 - 10 x + y^2 + 8;
f2[x_, y_] := x*y^2  + x - 10 y + 8;
f[x_, y_] := {f1[x, y], f2[x, y]} ;
x0 = {0, 0};

想在 x0 中评估 f[x_, y_],所以 f[0, 0]

我正在这样做,但没有工作,正确的做法是什么?

MatrixForm[f[{x0}]]

我得到 f[{{0, 0}}]

但想要 {8, 8}

I have

f1[x_, y_] := x^2 - 10 x + y^2 + 8;
f2[x_, y_] := x*y^2  + x - 10 y + 8;
f[x_, y_] := {f1[x, y], f2[x, y]} ;
x0 = {0, 0};

I want to evaluate f[x_, y_] in x0, so f[0, 0]

I am doing this but does not work, what is the correct way?

MatrixForm[f[{x0}]]

I get f[{{0, 0}}]

but want {8, 8} instead

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

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

发布评论

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

评论(1

落在眉间の轻吻 2024-12-22 00:45:41
In[61]:= f @@ x0

Out[61]= {8, 8}

出了什么问题?当您计算 f[{x0}] 时,它等于 f[{{0,0}}],它与 f< 的定义模式不匹配/代码>。 f@@x0,它是 Apply[ 的简写f,x0],替换 x0 的头部(其内部等于 List[0,0],因此它的头部是 List),与f。然后,您将得到与 f 的参数模式匹配的 f[0,0]。然后你会得到正确的结果。

In[61]:= f @@ x0

Out[61]= {8, 8}

What went wrong? When you evaluate f[{x0}] this equals f[{{0,0}}], which doesn't match the defined pattern for f. f@@x0, which is shorthand for Apply[f,x0], replaces the head of x0 (which internally equals List[0,0], hence its head is List), with f. You then get f[0,0] which matches the argument pattern of f. You then get the correct result.

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