Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write in Matlab a function that appreciates the fixed point iteration for a system of equations. The idea is:

$\begin{bmatrix} x{_{1}}^{m+1}\\ x{_{2}}^{m+1} \end{bmatrix}= \begin{bmatrix}y{_{1}}^{n}+hf{_{1}}(x{_{1}},x{_{2}})\\ y{_{2}}^{n}+hf{_{2}}(x{_{1}},x{_{2}}) \end{bmatrix}$

The iterations stop when $ |x_{1}^{m+1} -x_{1}^{m}|<TOL$ and $ |x_{2}^{m+1} -x_{2}^{m}|<TOL$ or when m arrives the limit of iterations M...

At the function, do I have to write : if ($|x_{1}^{m+1} -x_{1}^{m}|<TOL$ && $|x_{2}^{m+1} -x_{2}^{m}|<TOL $){ $y_{1}=x_{1}^{m+1}$; $y_{2}=x_{2}^{m+1}$; } ? But when only one of them is smaller than TOL how can it get its value ??

share|cite|improve this question
If only one of them is smaller than TOL, the iteration goes on. – Shuhao Cao Jun 2 '13 at 21:57
So is my "if" loop right, or should it be OR instead of AND ??? – Mary Star Jun 2 '13 at 22:00
Based on your description, definitely you should use &&. – Shuhao Cao Jun 2 '13 at 22:36
Could you take a look at my "for" loop?? Is this right?? [code]for m=1:M $x_{1}$(m+1)=y1n+h*$f_{1}$($tn+h,x_{1}(m),x-{2}(m)$); $x_{2}$(m+1)=y2n+h*$f_{2}$($tn+h,x_{1}(m),x_{2}(m)$); if (abs($x_{1}(m+1)-x_{1}(m))<TOL$ && abs($x_{2}(m+1)-x_{2}(m))<TOL$) $y_{1}=x_{1}(m+1)$; $y_{2}=x_{2}(m+1)$; return end x1(m)=x1(m+1); x2(m)=x2(m+1); end $y_{1}=x1(M)$; $y_{2}=x2(M)$;[/code] – Mary Star Jun 2 '13 at 22:41
Looks ok, but if you literally write y_{1} and put it in MATLAB, I believe MATLAB will give you a syntax error. – Shuhao Cao Jun 2 '13 at 22:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.