Azzera filtri
Azzera filtri

how to make function

2 visualizzazioni (ultimi 30 giorni)
poppy
poppy il 1 Dic 2022
Modificato: DGM il 1 Dic 2022
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 Commento
Stephen23
Stephen23 il 1 Dic 2022
Modificato: Stephen23 il 1 Dic 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?

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 1 Dic 2022
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?

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by