how to make function

์กฐํšŒ ์ˆ˜: 3 (์ตœ๊ทผ 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 Exchange์—์„œ Programming์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

์ œํ’ˆ


๋ฆด๋ฆฌ์Šค

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by