Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is a code for finding the root of the equation f(x) = exp(-x) - x in iteration method. When it runs, it shows the error,

File "fixedpointiteration.py", line 7
  i = i+1
  ^
SyntaxError: invalid syntax

Any solution? Thanks in advance.

i = 1
x[i] = 0
error[i] = 9999

while error[i] >= 0.1:
    x[i+1] = exp[-x[i]]
    error[i+1] = abs((((x[i+1] - x[i])/(x[i+1])*100))
    i = i+1

print x
print error
share|improve this question

put on hold as off-topic by user2357112, Kasra, Frédéric Hamidi, EdChum, jwodder 52 mins ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – user2357112, Kasra, Frédéric Hamidi, EdChum, jwodder
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Your parentheses are broken on the previous line. Use less of them, and don't be afraid to create intermediate variables. –  user2357112 55 mins ago
1  
You have a parenthesis problem on the previous line. –  Sam Bruns 55 mins ago
2  
You have omitted a close parenthesis in abs((((x[i+1] - x[i])/(x[i+1])*100)) –  Kasra 55 mins ago
    
another thing is x[i] = 0 is wrong –  haifzhan 51 mins ago

Browse other questions tagged or ask your own question.