Use te debugger to determine the first occurrence of a NaN. Type this in the command window:
Then run the code again. When Matlab stops, check the value of the trajectory. Most likely there is a pole and NaN or Inf is the correct numerical value. You can check this by:
By the way, vectorization can simplify the code:
function fn = plume5(t,Y, rho, cp)
fn = zeros(8, 1);
fn(1:4) = 1 ./ (rho(1:4)*cp) .* (760.91 - 1608.08 * Y(1:4) + ...
2449.22 * Y(1:4) .^ 2 - 2001.61 * Y(1:4) .^ 3 + ...
904.51 * Y(1:4) .^ 4 - 212.087 * Y(1:4) .^ 5 + 20.095 * Y(1:4) .^6 );
fn(5:6) = 1 ./ (rho(5:8) .* Y(5:8)) * (1.113 - 2.14 * Y(5:8) + ...
2.81 * Y(5:8) .^ 2 - 1.76 * Y(5:8) .^ 3 + 0.396 * Y(5:8) .^ 4 + ...
0.08694 * Y(5:8) .^ 5 - 0.0579 * Y(5:8) .^ 6 + 0.0077 * Y(5:8) .^ 7);
2 Comments
Jan (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/478846-why-do-i-get-nan-as-output#comment_742076
Sunetra CV (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/478846-why-do-i-get-nan-as-output#comment_742367
Sign in to comment.