how to make function
1 view (last 30 days)
Show older comments
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 Comment
Stephen23
on 1 Dec 2022
Edited: Stephen23
on 1 Dec 2022
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?
Answers (1)
Walter Roberson
on 1 Dec 2022
Example:
syms x1 x2
x = [x1;x2]
f(x) = (x1^3 - 2*x2^2 + 3*x1*x2 - 5)^3 + x1*x2
xstar = x * [-5 9]
f(xstar(1,:), xstar(2,:))
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?
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!