Afficher commentaires plus anciens
Can someone help me in spotting the NaN error? I need a pair of fresh eyes. The NaN error is DP. DP depends on P, MEAN_EQ, and STAND_EQ. But for some reason, Matlab shows P=39, MEAN_EQ=0, or STAND_EQ=0 in the workspace.
clc
clear all
format long
%% Definitions
STEP=1000;
START=61000;
END=300000;
DP=0;
DQ=START;
Q=END;
STD_SD = 7000; STD = 21000;
u = 60000;
STD_u = STD/sqrt(40);
while (DQ < Q)
MEAN1=1;
while MEAN1 < END;
MEAN_EQ = (1/(STD_u*sqrt(2*pi)))*exp(-0.5*((MEAN1-u)/STD_u)^2);
STAND=1;
P=0;
while STAND < END;
STAND_EQ = (1/(STD_SD*sqrt(2*pi)))*exp(-0.5*((STAND-STD)/STD_SD)^2);
a = pi/(sqrt(6)*STAND);
b = MEAN1 - (0.5772/a);
if(Q > DQ)
P = (a*((exp(-a*(DQ-b)))*(exp(-exp(-a*(DQ-b)))))*(1000000*0.005*((DQ-60000)^0.7)));
else
P = (a*((exp(-a*(DQ-b)))*(exp(-exp(-a*(DQ-b)))))*0);
end
DP = DP + P * STEP * MEAN_EQ * STEP * STAND_EQ * STEP;
STAND = STAND + STEP;
end
MEAN1 = MEAN1 + STEP;
end
end
Réponses (1)
Oleg Komarov
le 8 Fév 2011
Happens that P becomes NaN, and consequently DP, in:
exp(-a*(DQ-b)) * exp(-exp(-a*(DQ-b))) = inf * exp(-inf) = inf * 0 = NaN
When
a = 1.2825
DQ = 61000
b = 62001
I suggest to:
- Put a counter = 0, at the beginning of the second while statement, incrementing it at the end
- Set up a conditional break point on the counter (left click next to the line number, then right click --> set/modify condition: isnan(DP).
- After running the script, when it stops, remember the value of the counter and set condition to counter == value - 1. After re-executing it should stop on the values which generate the NaN as above.
Oleg
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!