Borrar filtros
Borrar filtros

Finding global minimum with rand

6 visualizaciones (últimos 30 días)
Ikenna Iwudike
Ikenna Iwudike el 2 de Abr. de 2022
Comentada: Ikenna Iwudike el 2 de Abr. de 2022
I'm supposed to use the MATLAB function "rand" to generate a large number of random vectors in 3-space, with coordinates between −6 and 6. Then I have to evaluate f at those points to find the minimum. But I don't know if I'm doing it correctly. My function is f(x, y,z) = x^4 + y^4 + z^4 − 3*x^2 − 8*y^2 − 6*x*z − 4*x*y − 10*z^2 + 6*y. Here's what I have so far:

Respuesta aceptada

Torsten
Torsten el 2 de Abr. de 2022
Editada: Torsten el 2 de Abr. de 2022
fumin = Inf;
for i = 1:100000
u = -6 + 12*rand(3,1);
fu = f(u);
if fu < fumin
umin = u;
fumin = fu;
end
end
  3 comentarios
Torsten
Torsten el 2 de Abr. de 2022
Editada: Torsten el 2 de Abr. de 2022
This error message cannot stem from my code above.
At least if f is defined as you showed us:
f = @(u) u(1)^4 ... etc.
Ikenna Iwudike
Ikenna Iwudike el 2 de Abr. de 2022
Oh ok, I didn't add that in. Thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by