Jump to content

Recommended Posts

Posted (edited)

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
Posted

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.
Posted

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???

Posted

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?

Posted

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???

Posted

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?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

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.