Bisection Method Not Working
조회 수: 9 (최근 30일)
이전 댓글 표시
I'm attempting to solve a simple problem using the bisection method, but I can't get it to work properly. Bascially, it's an orbital mechanics problem where 'a' is a distance, and 'del_t' is a time of flight traveled with that distance. I am solving for the value of 'a' given 'del_t'. The values of the upper ('high') and lower ('low') bounds are unknown, so my values right now are guesses. Since 'a' is a distance, the lower bound cannot obviously be lower than 0. Note that the ii and jj counters are just troubleshooting tools that I've used to see which if conditions are running and how many times. For some reason, the loop runs infinitely with the value of 'a' capping out at the value of 'high'. It's probably something small and any help would be greatly appreciated!
a = 5000;
s = 1.123675421589143e+04
c = 8.795508431782857e+03
high = 30000;
low = 0;
del_t = 10000;
ii = 1;
jj = 1;
while abs(tof-del_t) > 10e-3
del_t = ((a^(3/2))/sqrt(mu))*((2*asin(sqrt(s/(2*a))))-...
(2*asin(sqrt((s-c)/(2*a))))-(sin(2*asin(sqrt(s/(2*a))))-...
sin(2*asin(sqrt((s-c)/(2*a))))));
if del_t < tof
low = a;
ii = ii+1;
else
high = a;
jj = jj+1;
end
a = (low+high)/2;
end
댓글 수: 4
James Tursa
2016년 11월 22일
I got the complex result at the very first iteration using the first values of a and s shown in your code. So the problem is immediate.
답변 (1개)
James Tursa
2016년 11월 22일
편집: James Tursa
2016년 11월 22일
It is not clear to me that your initial guesses are even bracketing your desired tof. So there will be no hope that your bisection method will converge. E.g.,
>> a = (low+high)/2
a =
5.0000e+10
>> f(a)
ans =
875.1905
>> f(high)
ans =
875.1905
>> tof
tof =
1.1257e+03
Also, your function f appears to be monotonically decreasing, not increasing, so your high & low are reversed. E.g., making a couple of changes I can get convergence:
mu = 3.986004418e5; % km^3/s^2
a = 5000;
c = 9.674486239589160e+03;
s = 1.167624311979458e+04;
tof = 1.1257e+03;
f = @(x) ((x^(3/2))/sqrt(mu))*((2*asin(sqrt(s/(2*x))))-...
(2*asin(sqrt((s-c)/(2*x))))-(sin(2*asin(sqrt(s/(2*x))))-...
sin(2*asin(sqrt((s-c)/(2*x))))));
low = 7500;
high = 20000;
if( (f(low)-tof)*(f(high)-tof) > 0 )
error('Initial guesses do not bracket desired tof');
end
del_t = 0;
while abs(del_t-tof) > 1e-3
a = (low+high)/2;
fa = f(a);
if( imag(fa) )
disp(a);
disp(fa);
error('f(a) is complex');
end
if fa < tof
high = a;
else
low = a;
end
del_t = fa;
end
(But, again, I would advise that you annotate all of your lines with constants on them like I have annotated the first line)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Array and Matrix Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!