mathmari Posted June 2, 2013 Share Posted June 2, 2013 (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 June 2, 2013 by mathmari Link to comment Share on other sites More sharing options...
md65536 Posted June 3, 2013 Share Posted June 3, 2013 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. 1 Link to comment Share on other sites More sharing options...
mathmari Posted June 3, 2013 Author Share Posted June 3, 2013 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??? Link to comment Share on other sites More sharing options...
md65536 Posted June 3, 2013 Share Posted June 3, 2013 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? 1 Link to comment Share on other sites More sharing options...
mathmari Posted June 3, 2013 Author Share Posted June 3, 2013 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??? Link to comment Share on other sites More sharing options...
md65536 Posted June 3, 2013 Share Posted June 3, 2013 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? 1 Link to comment Share on other sites More sharing options...
mathmari Posted June 3, 2013 Author Share Posted June 3, 2013 Ok! Thanks!!! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now