フィルターのクリア

how to make function

2 ビュー (過去 30 日間)
poppy
poppy 2022 年 12 月 1 日
編集済み: DGM 2022 年 12 月 1 日
I have this given function
𝑓(𝒙)=(𝑥1^2+𝑥2 −2)^2+(𝑥1 +𝑥2^2−4)^2+𝑥1*𝑥2
I need to make a function that computes that value of f(x*) at the point x*[1 1], how would i go about doing this?
  1 件のコメント
Stephen23
Stephen23 2022 年 12 月 1 日
編集済み: Stephen23 2022 年 12 月 1 日
Original question by Anujan Sivabalan retrieved from Google Cache:
how to make function
I have this given function
𝑓(𝒙)=(𝑥1^2+𝑥2 −2)^2+(𝑥1 +𝑥2^2−4)^2+𝑥1*𝑥2
I need to make a function that computes that value of f(x*) at the point x*[1 1], how would i go about doing this?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 12 月 1 日
Example:
syms x1 x2
x = [x1;x2]
x = 
f(x) = (x1^3 - 2*x2^2 + 3*x1*x2 - 5)^3 + x1*x2
f(x1, x2) = 
xstar = x * [-5 9]
xstar = 
f(xstar(1,:), xstar(2,:))
ans = 
Reminder: if x is a 1 x 2 vector instead of a 2 x 1 vector, then x * [1 1] would be a (1 x 2) inner product with (1 x 2) and that would fail because the * inner product operation requires that the number of columns of the first operand be the same as the number of rows of the second operand. So [1 x 2] * [1 x 2] would fail. And that tells us that x must be [x1; x2] in a column, a 2 x 1 -- but then x * [1 1] gives a 2 x 2 result
When you try to define a symbolic function with a vector of variables, like in this case, MATLAB permits the syntax of assigning to f(x) to create the function, but the function that is created will have two parameters not one. That is why the xstar value has to be split into x1 and x2 portions to pass it in to the function. Should the dividing have been done by rows or by columns? I'll leave that to you to think about?

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by