Effacer les filtres
Effacer les filtres

Invalid syntax at 'x'. Possibly a ), }, ] is missing.

14 vues (au cours des 30 derniers jours)
Stefan
Stefan le 5 Oct 2014
Commenté : Stefan le 5 Oct 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

Réponse acceptée

Image Analyst
Image Analyst le 5 Oct 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 &
  1 commentaire
Stefan
Stefan le 5 Oct 2014
Thank you very much! I knew it was a silly mistake...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by