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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
ravi poudel
am 6 Jul. 2022
Kommentiert: ravi poudel
am 6 Jul. 2022
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 Kommentare
KSSV
am 6 Jul. 2022
Check the formula for dydx...this is giving -inf....you need to check the brackets and power. Are they correctly represented?
Akzeptierte Antwort
Sam Chak
am 6 Jul. 2022
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)));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!