Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Jos (10584)
Jos (10584) le 5 Mar 2014
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 ..

Plus de réponses (0)

Catégories

En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by