필터 지우기
필터 지우기

Why is there an error? Unbalanced or unexpected parenthesis or bracket.

조회 수: 2 (최근 30일)
Error: File: golden.m Line: 1 Column: 21
Unbalanced or unexpected parenthesis or bracket.
function golden(sqrt(2), sqrt(28))
t=[sqrt(2):0.01:sqrt(28)];
plot(t, arrayfun(@f,t));
hold on
tol=10^(-12);
r=(3-sqrt(5))/2;
c=sqrt(2)+r*(sqrt(28)-sqrt(2));
d=sqrt(28)-r*(sqrt(28)-sqrt(2));
fa=f(sqrt(2));
fb=f(sqrt(28));
fc=f(c);
fd=f(d);
while (sqrt(28)-sqrt(2)>tol)
if (fc<fd)
sqrt(28)=d;
fb=fd;
d=c;
fd=fc;
c=sqrt(2)+r*(sqrt(28)-sqrt(2));
fc=f(c);
plot(c,fc,'r*');
else
sqrt(2)=c;
fa=fc;
c=d;
fc=fd;
d=sqrt(28)-r*(sqrt(28)-sqrt(2));
fd=f(d);
plot(d,fd,'r*');
end
end
fprintf('Minimum found at x=%.12f \n', (sqrt(2)+sqrt(28))/2, f(sqrt(2)+sqrt(28))/2);
hold off
end

채택된 답변

Jos (10584)
Jos (10584) 2014년 3월 5일
sqrt(2) and sort(28) are not a valid variable name
replace sqrt(2) and sqrt(28) every with A and B
function golden (A,B)
t = A:0.01:B ;
.. etc ..

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by