How could I program a "for loop" in Matlab to calculate the function's minimum value?
조회 수: 1 (최근 30일)
이전 댓글 표시
How could I program a "for loop" in Matlab to calculate the function's minimum value?
The goal is to locate the function G's minimum value point that corresponds to the particular parameter b=[1 2 3 4 5]. Like:
syms x
for b=1:1:5;
G=x.^2-b.*x+1;
f=inline(G);
x=fminbnd(f,0,10)
end
댓글 수: 1
Stephen23
2022년 6월 22일
Rather than combining slow symbolic maths with deprecated and inefficient INLINE(), you should use:
답변 (2개)
Stephen23
2022년 6월 22일
X = [1,2,3,4,5];
Y = nan(size(X));
for k = 1:numel(X)
b = X(k);
G = @(x) x.^2 - b.*x + 1;
Y(k) = fminbnd(G,0,10);
end
plot(X,Y,'*')
댓글 수: 0
Star Strider
2022년 6월 22일
G = @(x,b) x.^2-b.*x+1;
b=1:1:5;
for k = 1:numel(b)
xv(k) = fminsearch(@(x)G(x,b(k)), rand);
end
xv
The first derivative of ‘G’ is simply ‘2*x-b’ so an analytic solution is:
xq = b/2
Giving the same result.
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!