# Loop until convergence of two variables

I have the following program which i need to repeat steps until until two variables converge and I want this to be printed with the number of iterations:

What I have :

Input variables:

xTensionLaminate = 1325
SigmaFail = xTensionLaminate*VF
ÏƒApplied = xTensionLaminate*0.25
VF = 0.6

then the program is steps:

1.Apply tension part of the cycle. The applied stress on the fibers is

ÏƒAppliedFibers = ÏƒApplied/VF

2.All fibers with strength less than SigmaAppliedFibers fail. The fraction of fibers that have failed are:[%][7]

FibersTensionFail1 = CDF[NormalDistribution[795, 50 ], ÏƒAppliedFibers]

3.Fraction of fibers that remain[%][8]

FibersTensionRemaining1 = 1 – FibersTensionFail1

4.The remaining fibers now are equally loaded by the new stress[Mpa]

ÏƒAppliedFibersNew = ÏƒAppliedFibers/(1 – FibersTensionFail1)

5.Repeat steps corresponding to equations [7][8] until either convergence of (FibersTensionFail1 = FibersTensionRemaining1)<1 or all fibers fail FibersTensionFail1=1 This iteration needs to be done until FibersTensionRemaining and FibersTensionFail are equal or either one equal to unity. So I try to put this in a While loop. While[FibersTensionRemaining <= FibersTensionFail, FibersTensionFail = CDF[NormalDistribution[795, 50 ], ÏƒAppliedFibers]; FibersTensionRemaining = 1 - FibersTensionFail; ÏƒAppliedFibersNew = ÏƒAppliedFibers/(1 - FibersTensionFail) My question here is that in the NormalDistribution the ÏƒAppliedFibers variable changes at each iteration according to the formula ÏƒAppliedFibersNew = ÏƒAppliedFibers/(1 - FibersTensionFail) so the new ÏƒAppliedFibers comes back into FibersTensionFail = CDF[NormalDistribution[795, 50 ], ÏƒAppliedFibers]; where after doing this n number of times there should be a converge in FibersTensionRemaining and FibersTensionFail Please help on this as i cannot find the way Thanks, Nick EDIT: Note: The name of the Variables are slightly changed here but are the same. What I do as a code manually and I stop the calculation: 1st iteration: AccountingForm[ FibersFailed1 = CDF[NormalDistribution[795, 50 ], StressAppliedFibers1] , 30] = 0.0000005919095091896093 AccountingForm[FibersRemaining1 = 1 - FibersFailed1, 31] = 0.999999408090491 StressAppliedFibers2 = StressAppliedFibers/(1 - FibersFailed1) = 552.084 2nd iteration: AccountingForm[ FibersFailed2 = CDF[NormalDistribution[795, 50 ], StressAppliedFibers2], 30] = 0.000000591909509834259 AccountingForm[FibersRemaining2 = 1 - FibersFailed2, 30]=0.99999940809049 StressAppliedFibers3 = StressAppliedFibers/(1 - FibersFailed2)=552.084 3rd Iteration: AccountingForm[ FibersFailed3 = CDF[NormalDistribution[795, 50 ], StressAppliedFibers3] , 30]=0.0000005919095098342807 AccountingForm[FibersRemaining3 = 1 - FibersFailed3, 30]= 0.99999940809049 StressAppliedFibers4 = StressAppliedFibers/(1 - FibersFailed3)=552.084 4th Iteration: AccountingForm[ FibersFailed4 = CDF[NormalDistribution[795, 50 ], StressAppliedFibers4] , 30]=0.0000005919095098342807 AccountingForm[FibersRemaining4 = 1 - FibersFailed4, 30]= 0.99999940809049 StressAppliedFibers5 = StressAppliedFibers/(1 - FibersFailed4)=552.084 So what we can see here is that after the 3rd iteration the values remain the same no matter how many iterations are made again. What I need to figure how to make the loop which will take these variables and change them until the values converge and then print the number of iterations and also the final value of The FibersRemaining and StressAppliedFibers. Simple yes but I do not know how to add to a loop changeable variables. thanks N =================      What is â€œSigmaFail = xTensionLaminate*VF, 30] â€? – Apple Jun 22 '14 at 16:04      Also "FibersTensionFail1 = CDF[NormalDistribution[795, 50 ], ÏƒAppliedFibers" – Apple Jun 22 '14 at 16:06      @Chenminqi it's a typo from copying from my mathematica file. it is: â€œSigmaFail = xTensionLaminate*VF. ignore the 30]. i will edit it above now. Also FibersTensionFail1 = CDF[NormalDistribution[795, 50 ], ÏƒAppliedFibers is edited above to FibersTensionFail1 = CDF[NormalDistribution[795, 50 ], ÏƒAppliedFibers] – Nikolas Jun 22 '14 at 16:14 2   never use goto. Try reworking your code using While – george2079 Jun 22 '14 at 16:20 2   p=NestList[{CDF[NormalDistribution[795,50],#[[2]]],#[[2]]/(1‌​-#[[1]])}&,{CDF[Norm‌​alDistribution[795,5‌​0],\[Sigma]AppliedFi‌​bers],\[Sigma]Applie‌​dFibers},10^5];ListP‌​lot[#,MaxPlotPoints-‌​>1000]&/@Transpose@p
– Dr. belisarius
Jun 22 ’14 at 17:08

=================

2

=================

xTensionLaminate = 1325;
sApplied = xTensionLaminate*0.25;
VF = 0.6;
SigmaFail = xTensionLaminate*VF;
sAppliedFibers = sApplied/VF;

p = NestWhileList[{CDF[NormalDistribution[795, 50], #[[2]]], #[[2]]/(1 – #[[1]])} &,
{CDF[NormalDistribution[795, 50], sAppliedFibers], sAppliedFibers},
#[[1]] < .5 &, 1]; ListLinePlot[Log@p[[All, 1]], PlotRange -> All]

Thank you this graph is helpful but it does not show where the converge is of the two variables ‘FibersTensionFail and ‘FibersTensionRemaining’
– Nikolas
Jun 22 ’14 at 20:03

xTensionLaminate = 1325;
sApplied = xTensionLaminate*0.25;
VF = 0.6;
sAppliedFibers = sApplied/VF
fibersTensionFail = CDF[NormalDistribution[795, 50], sAppliedFibers];
fibersTensionRemaining = 1 – fibersTensionFail;
q = First@Last@Reap@
While[1 – CDF[NormalDistribution[795, 50], sAppliedFibers] > 0,
fibersTensionFail = CDF[NormalDistribution[795, 50], sAppliedFibers];
fibersTensionRemaining = 1 – fibersTensionFail;
sAppliedFibers = sAppliedFibers/(1 – fibersTensionFail);
Sow[{fibersTensionFail, fibersTensionRemaining}]
];

ListLinePlot[Log@q[[All, 1]], PlotRange -> All]