my script runs but the while loop doesn't work

1 visualizzazione (ultimi 30 giorni)
Rich
Rich il 27 Feb 2015
Commentato: Image Analyst il 28 Feb 2015
I am trying to run a script with a while loop to run until a certain tolerence is met. The script runs but its seems to just miss out the loop and doesn't give any results for this. Any help would be great, thank you in advance.
mu = [4 5 2e7 1e-4]; % Mean values of P, L, E & I respecitvley
sigma = [1 0 0.5e7 0.2e-4]; % Standard deviations of P, L, E & I respecitvley
% Scale and Location parameters
alpha = 1.2825/sigma(1);
delta = mu(1) - 0.5772/alpha;
% Coordinates of inital design point
E1 = mu(3);
I1 = mu(4);
P1 = mu(1);
% Density Funcrion at P1 (fP1)
fP1 = alpha*exp(-(P1-delta)*alpha-exp(-(P1-delta)*alpha));
%Cumlative Distribution value at P1 (FP1)
FP1 = exp(-exp(-(P1-delta)*alpha));
% standard deviation and mean value of the equivalent variable at P1
cdfP1 = norminv(FP1); %Inverse Gaussian CDF
sndfP1 = (1/sqrt(2*pi))*exp(-0.5*(cdfP1)^2); %standard normal density function
sigmaP1dash = sndfP1 / fP1;
muP1dash = P1 - cdfP1*sigmaP1dash;
% Function value and gradients of the limit state function at mean value
% point
gi1 = feval('performance4_5', E1, I1, P1);
dEi1 = feval('derivative_dE', E1, I1, P1);
dIi1 = feval('derivative_dI', E1, I1, P1);
dPi1 = feval('derivative_dP', E1, I1, P1);
% Safety index (beta) using mean value method and its directional cosine
% (alpha)
mugi1 = gi1; % mean of performance function
sigmagi1 = sqrt(((dEi1)*sigma(3))^2+((dIi1)*sigma(4))^2+((dPi1)*sigmaP1dash)^2); % standard devitation of performance fucntion
betai1 = 2.6383; % Safety Index
alphaE = -dEi1 * sigma(3) / sigmagi1;
alphaI = -dIi1 * sigma (4) / sigmagi1;
alphaP = -dPi1 * sigmaP1dash / sigmagi1;
% Coordinates for new design point
E2 = mu(3) + betai1 * sigma (3) * alphaE;
I2 = mu(4) + betai1 * sigma (4) * alphaI;
P2 = muP1dash + betai1 * sigmaP1dash * alphaP;
uE2 = (E2 - mu(3)) / sigma(3);
uI2 = (I2 - mu(4)) / sigma(4);
uP2 = (P2 - muP1dash) / sigmaP1dash;
% Iteration 2
% Density function value at P2 (fP2)
fP2 = alpha*exp(-(P2-delta)*alpha-exp(-(P2-delta)*alpha));
% CDF at P2 (FP2)
FP2 = exp(-exp(-(P2-delta)*alpha));
% standard deviation and mean value of the equivalent variable at P2
cdfP2 = norminv(FP2); %Inverse Gaussian CDF
sndfP2 = (1/sqrt(2*pi))*exp(-0.5*(cdfP2)^2); %standard normal density function
sigmaP2dash = sndfP2 / fP2;
muP2dash = P2 - cdfP2*sigmaP2dash;
% Fucntion value and gradients of limit state function at X2(E2,I2,P2)
gi2 = feval('performance4_5', E2, I2, P2);
dEi2 = feval('derivative_dE', E2, I2, P2);
dIi2 = feval('derivative_dI', E2, I2, P2);
dPi2 = feval('derivative_dP', E2, I2, P2);
% initial beta for loop and directional cosine
sigmagi2 = sqrt(((dEi2)*sigma(3))^2+((dIi2)*sigma(4))^2+((dPi2)*sigmaP1dash)^2);
betai2 = (gi2 -(dEi2*sigma(3)*uE2)-(dIi2*sigma(4)*uI2)-(dPi2*sigmaP2dash*uP2))/sigmagi2;
alphaE = -dEi2 * sigma(3) / sigmagi2;
alphaI = -dIi2 * sigma (4) / sigmagi2;
alphaP = -dPi2 * sigmaP2dash / sigmagi2;
% Iteration 3 - new design points
E3 = mu(3) + betai2 * sigma (3) * alphaE;
I3 = mu(4) + betai2 * sigma (4) * alphaI;
P3 = muP2dash + betai2 * sigmaP2dash * alphaP;
uE3 = (E3 - mu(3)) / sigma(3);
uI3 = (I3 - mu(4)) / sigma(4);
uP3 = (P3 - muP2dash) / sigmaP2dash;
% check beta convergence
gamma = abs(betai2 - betai1)/betai1;
while gamma < 0.001
fP3 = alpha*exp(-(P3-delta)*alpha-exp(-(P3-delta)*alpha));
FP3 = exp(-exp(-(P3-delta)*alpha));
cdfP3 = norminv(FP3); %Inverse Gaussian CDF
sndfP3 = (1/sqrt(2*pi))*exp(-0.5*(cdfP3)^2); %standard normal density function
sigmaP3dash = sndfP3 / fP3;
muP3dash = P3 - cdfP3*sigmaP3dash;
gi3 = feval('performance4_5', E3, I3, P3);
dEi3 = feval('derivative_dE', E3, I3, P3);
dIi3 = feval('derivative_dI', E3, I3, P3);
dPi3 = feval('derivative_dP', E2, I2, P2);
% initial beta for loop and directional cosine
sigmag = sqrt(((dEi3)*sigma(3))^2+((dIi3)*sigma(4))^2+((dPi3)*sigmaP3dash)^2);
betai1 = betai2;
betai2 = (gi3 -(dEi3*sigma(3)*uE3)-(dIi3*sigma(4)*uI3)-(dPi3*sigmaP3dash*uP3))/sigmagi2;
alphaE = -dEi3 * sigma(3) / sigmagi3;
alphaI = -dIi3 * sigma (4) / sigmagi3;
alphaP = -dPi3 * sigmaP3dash / sigmagi3;
% Iteration 3 - new design points
E4 = mu(3) + betai2 * sigma (3) * alphaE;
I4 = mu(4) + betai2 * sigma (4) * alphaI;
P4 = muP3dash + betai2 * sigmaP3dash * alphaP;
uE4 = (E4 - mu(3)) / sigma(3);
uI4 = (I4 - mu(4)) / sigma(4);
uP4 = (P4 - muP3dash) / sigmaP3dash;
gamma = (betai2 - betai1)/betai1;
end
  2 Commenti
Geoff Hayes
Geoff Hayes il 28 Feb 2015
Rich - put a breakpoint at the line
gamma = abs(betai2 - betai1)/betai1;
and then run your code. When the debugger pauses at this line, step over it and observe the value of gamma. What is it? Is it greater than 0.001?
Image Analyst
Image Analyst il 28 Feb 2015
This link will definitely help you solve this problem and almost all others: click here.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by