Path: news.mathworks.com!not-for-mail
From: "Dave Brown" <s0674729@sdms.ed.ac.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Help please, how to write simple iterations and for loops
Date: Tue, 3 Nov 2009 15:00:20 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 15
Message-ID: <hcpgi4$mtt$1@fred.mathworks.com>
Reply-To: "Dave Brown" <s0674729@sdms.ed.ac.uk>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257260420 23485 172.30.248.38 (3 Nov 2009 15:00:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Nov 2009 15:00:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2074632
Xref: news.mathworks.com comp.soft-sys.matlab:582064


Im tryng to write an iteration using a "for" loop concerning this equation:

PI = 0.5*((PI+1) + (PI-1) + ((deltaX * 3 * 0.2)/(0.00001))*(((PI+1) - (PI-1))/(2*deltaX)) + (((deltaX)^2 * 6 * 0.01 * 0.2 * 2)/0.00001^3))

The equation is concerning pressure differences over change in length (deltaX) where PI is just the next pressure (e.g. P1, P2, P3...).  I need to find P1 over a range of values of deltaX:

>> deltaX = 0,0.005,0.01,0.015,0.02,0.025,0.03,0.035,0.04,0.045,0.05,0.055,0.06,0.065,0.07,0.075,0.08,0.085,0.00,0.095,0.1

My first problem is that im not sure on how to get a rage of values for P1 from each different deltaX, although I am taking (PI+1)=0 and (PI-0)=0 for my first set of pressures (P1).  My second problem is I need to not only find P1 but rather keep on iterating the equation untill I get a convergance.  Now I think I know what to do to get values for P1 - put deltaX into a matrix and slove for a range of P1's - but how do i create an overall "for" loop which will keep on iterating this equation using (PI-1) and (PI+1)=0

Any help in pointing me in the right direction would be fantastic and Im sorry if this is presented in an odd or confusing way, it's one of the first times I've ever used MATLAB or any other maths software so I'm still very much finding my feet.

Thanks very much,

Dave