I am tyring to implement a code with a loop. But my output variable is a NaN, but it must be a number in output. I am not sure what's wrong. Can anyone help?

1 次查看(过去 30 天)
a = (D1/2)-(D2_cor/2) % the major axis the ellipse - ??
b = a*0.75
ellipse = [a,b]
ellipse_length = 0 % inlitialize integral
integral_start = 0 % Integrate from ...
ns = 18 % number of streamlines
np = 40 % number of points per streamlines
% Integrate to end of ellipse , minus a small part to avoid infinite integral. ..??
integral_end = ellipse(1) - 0.0001
integral_step = 100000 % integral step
dx = (integral_end - integral_start)/integral_step % initializing dx
%now we make integral start to find the length of the ellipse along ring
for x = integral_start : dx : integral_end
dydx = (1/2)*ellipse(2)*(1-(x/ellipse(1)^2)^(-0.5))*(-(2*x/(ellipse(1)^2)));
ellipse_length = ellipse_length + sqrt(1+(dydx)^2)*dx;
end
% here the output in the variable "ellipse_length" is a NaN. I don't know whats wrong. Can anyone suggest me what is wrong here?

采纳的回答

Sam Chak
Sam Chak 2022-7-6
Please check your code if singularity occurs in this line:
dydx = (1/2)*ellipse(2)*(1-(x/ellipse(1)^2)^(-0.5))*(-(2*x/(ellipse(1)^2)));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by