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?
2 个评论
KSSV
2022-7-6
Check the formula for dydx...this is giving -inf....you need to check the brackets and power. Are they correctly represented?
采纳的回答
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 Center 和 File 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!