Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!l19g2000yqb.googlegroups.com!not-for-mail
From: Nathan <ngreco32@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: j not equal to i
Date: Fri, 22 Jan 2010 11:23:52 -0800 (PST)
Organization: http://groups.google.com
Lines: 98
Message-ID: <f3906732-3482-4681-9ed8-758e2b60cb33@l19g2000yqb.googlegroups.com>
References: <hjck1s$25s$1@fred.mathworks.com> <2047bb41-198b-4a35-9003-bc68cc89418d@l11g2000yqb.googlegroups.com> 
	<hjcrag$mu1$1@fred.mathworks.com>
NNTP-Posting-Host: 198.206.219.34
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1264188232 18017 127.0.0.1 (22 Jan 2010 19:23:52 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 22 Jan 2010 19:23:52 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: l19g2000yqb.googlegroups.com; posting-host=198.206.219.34; 
	posting-account=_KeVcAoAAAB7j3xn35ujaQ0BoQhuzwJP
User-Agent: G2/1.0
X-HTTP-Via: 1.1 wwwproxy-son-ca-02.ca.sandia.gov:80 (squid/2.5.STABLE14)
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) 
	Gecko/20091221 Firefox/3.5.7,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:600984

On Jan 22, 10:38 am, "Ender " <jr...@msstate.edu> wrote:
> Thanks, I will try your example.
>
>  In my current code I cannot figure out why MATLAB is not continuing my while loop. At the end of the code and outside of the while loop I wrote a code to display that the maximum number of iterations have been exceeded. However, my code does this at k=2 instead of k=100. I think it is something simple that I am leaving out or forgetting, but I can not figure out what it is.
>
> Here is my code:
>
> % Set the number of iterations to perform
> N=100;
>
> % Set the Tolerance
> TOL=10e-3;
>
> % Initial Vector
> XO=[0;0;0];
>
> % The Matrix A
> A=[3,-1,1;3,6,2;3,3,7];
>
> % The Matrix b
> b=[1;0;4];
>
> % % Returns the two integers in two separate variables.
> [n,n]=size(A);
>
> % Step 1
> k=1:N;
>
> % Step 2
> while (k <= N)
>       % initialize s1a + s1b
>       s1a=0;
>       s1b=0;
>       % Step 3
>       for i=1:n
>
>           % To account for not using the j=i in the algorithm
>           for j=1:i-1
>               s1a=s1a+(A(i,j))*XO(j)+b(i);
>           end
>           for j=i+1:n
>               s1b=s1b+(A(i,j))*XO(j)+b(i);
>           end
>
>           % Add the sections before & after j not equal to i
>           sT=s1a+s1b;
>
>           x(i)=-sT/A(i,i);
>
>           % Step 4
>           if abs(x(i)-XO)<TOL
>              display(' The Procedure was successful')
>              % Output x
>              x(i);
>              % Stop the Algorithm
>              return
>           end
>       end      
>          % Step 5
>          k=k+1;
>
>       % Step 6
>       % Update XO
>       for i=1:n
>           XO(i)=x(i);
>       end
> end  
>
> % Step 7
> % Ouput to screen
> display('Maximum number of iterations exceeded')
>
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <2047bb41-198b-4a35-9003-bc68cc894...@l11g2000yqb.googlegroups.com>...
> >  --Ender--
> > I thought of these two ways off the top of my head.
> > They're not necessarily better than splitting it up into two for loops
> > which is I think what you were hinting at.
>
> > j=5;
> > % Method 1
> > for k = [1:(j-1), (j+1):10]
> >    k % Show index in command window.
> > end
> > % Method 2
> > for m = 1:10
> >    if m ~= j
> >            m % Show index in command window.
> >    end
> > end
>
>