Jump to content

Need Help at fixed point iteration code!

Featured Replies

Hi!!

I want to use the fixed point iteration for the Backward Euler Method for 2x2 systems(in Matlab), I wrote the following that appreciates it:

function [Y1,Y2]=stage(y1n,y2n,h,tn)
    M=5;
    TOL=1e-5;
    x1(1)=y1n;
    x2(1)=y2n;
    for m=1:M
        x1(m+1)=y1n+h*S(tn+h,x1(m),x2(m));
        x2(m+1)=y2n+h*G(tn+h,x1(m),x2(m));
        if (abs(x1(m+1)-x1(m))<TOL || abs(x2(m+1)-x2(m))<TOL)
            Y1=x1(m+1);
            Y2=x2(m+1);
            return
        end
        x1_m=x1(m+1);
        x2_m=x2(m+1);
    end
    Y1=x1(M);
    Y2=x2(M);
 

Could you tell me if the "if" loop has to stop either if |(x1(m+1)-x1(m)|<TOL or |x2(m+1)-x2(m)|<TOL , or if both of them are <TOL ????And if both have to be <TOL, could you tell me how I wite this in Matlab???

Edited by mathmari

Could you tell me if the "if" loop has to stop either if |(x1(m+1)-x1(m)|<TOL or |x2(m+1)-x2(m)|<TOL , or if both of them are <TOL ????And if both have to be <TOL, could you tell me how I wite this in Matlab???[/size][/font][/color]

Assuming it's like C, || means "or", meaning the condition is true if either of those things is true. && would mean "and", requiring both to be true.
  • Author

And which of them should I use in this function in the "if" loop??? "OR" or "AND" ???

The loop has to stop when both of them are true? or is it enough when only one is smaller than TOL???

And which of them should I use in this function in the "if" loop??? "OR" or "AND" ???

The loop has to stop when both of them are true? or is it enough when only one is smaller than TOL???

Oh, I see.

 

Well, what does it mean if one is < TOL? What would it mean if the other was > TOL?

  • Author

When one is <TOL, we consider that it appreciates the fixed point... I think that both of them should be <TOL, so I have to use "AND". Right???

When one is <TOL, we consider that it appreciates the fixed point... I think that both of them should be <TOL, so I have to use "AND". Right???

I think so. If they're each convergent, there should be no harm in extra iterations, right? Why would you stop if one of the values is close enough but not the other?

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.