Invalid syntax at 'x'. Possibly a ), }, ] is missing.
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stefan
el 5 de Oct. de 2014
Comentada: Stefan
el 5 de Oct. de 2014
Hi everyone, I'm writing this code for a hw problem in class. for some reason, I'm getting a syntax error for "Unexpected Matlab expression". I cannot figure out what is wrong, but it seems to be a simple error that I'm just making a silly mistake on. It's giving me the error on the 'x' variable in line 9, column 15. Any help is greatly appreciated. Thank you!
x=0; %set starting value
nmax=10; %set max number of iterations
eps=1; %initialize error bound eps
xvals=x; %initialize array of iterates
n=0; %initialize n (counts iterations)
while eps>=1e-5&n<=nmax %set while-conditions
y=x-(x^3-3x^2+6x-30)/(3x^2-6x+6) %compute next iterate
xvals=[xvals;y]; %write next iterate in array
eps=abs(y-x); %compute error
x=y;n=n+1; %update x and n
end
0 comentarios
Respuesta aceptada
Image Analyst
el 5 de Oct. de 2014
These two lines are fixed:
while eps>=1e-5 && n<=nmax %set while-conditions
y=x-(x^3-3*x^2+6*x-30)/(3*x^2-6*x+6) %compute next iterate
When you multiply numbers by anything, you need to use *, like 3*x, not just 3x. Also you need && in your while test, not &
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!