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:

 채택된 답변

Torsten
Torsten 2022년 4월 2일
편집: Torsten 2022년 4월 2일

0 개 추천

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

Ikenna Iwudike
Ikenna Iwudike 2022년 4월 2일
편집: Ikenna Iwudike 2022년 4월 2일
I'm getting these errors when I use that code:
Array indices must be positive integers or logical values.
Error in sym/subsref (line 909)
R_tilde = builtin('subsref',L_tilde,Idx);
Torsten
Torsten 2022년 4월 2일
편집: Torsten 2022년 4월 2일
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 2022년 4월 2일
Oh ok, I didn't add that in. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 4월 2일

댓글:

2022년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by