Thread Subject: Help please, how to write simple iterations and for loops

Subject: Help please, how to write simple iterations and for loops

From: Dave Brown

Date: 3 Nov, 2009 15:00:20

Message: 1 of 2

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

Subject: Help please, how to write simple iterations and for loops

From: ImageAnalyst

Date: 3 Nov, 2009 18:15:04

Message: 2 of 2

Dave:
What exactly is PI+1 or PI-1? Is that the P value at the index after
and before the current index (if so, you need to have the complete PI
for all elements already calculated so that you can use them in the
next pass)? In other words, if you're calculating P(k) and it depends
on P(k+1) but you haven't calculated P(k+1) already, then you're out
of luck.

Or is it literally the PI value plus or minus 1 (which is impossible
because you haven't calculated PI yet)?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
for loop Dave Brown 3 Nov, 2009 10:04:07
iteration Dave Brown 3 Nov, 2009 10:04:07
help Dave Brown 3 Nov, 2009 10:04:07
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com