Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Jos (10584)
Jos (10584) el 5 de Mzo. de 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 ..

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by