Register to reply 
Bisection method in fortran 90 
Share this thread: 
#1
Dec1412, 03:47 AM

P: 126

Bisection method for the equation x3−2x−2 = 0 which has a single root
between x=−4 and x = 2. here's the code I have
Here are the Bisection Method formulas xm = (xl+xu)/2 


#2
Dec1412, 04:13 AM

Sci Advisor
P: 2,751

The code at the line starting: "if fxnew>0 then" can never execute. Take a close look and see if you can tell me why?
A couple of other points. 1. Even if you fix the above problem, your code may never terminate. Requiring exact (FP) equality with zero is a bad idea. 2. There's no real reason to use to goto in this code. You should look at alternative methods of program flow control. 3. It will really help you keep track of your code if you start making use of indentation. 


#3
Dec1412, 04:15 AM

P: 126

I'm guessing coz there is no "end if"?
I don't know. sorry.. How can I do the iteration here? Thanks for the help 


#4
Dec1412, 04:26 AM

Sci Advisor
P: 2,751

Bisection method in fortran 90
I'm surprised that the program even compiled without the "end if" statements. (BTW. does it actually compile?) 


#5
Dec1412, 04:28 AM

P: 126

Can you please please help me? How can I put the conditions above and do the iteration? Please? thanks.
Yes it did compile. 


#6
Dec1412, 06:51 AM

Sci Advisor
P: 2,751

I'll look at one section:



#7
Dec1412, 08:52 AM

P: 182

... and don't forget to correct your inital conditions.



#8
Dec1412, 08:55 AM

P: 126

Ow. So it should be
xl=xl xu=xnew Correct? Then? What should I do? 


#9
Dec1412, 09:13 AM

Sci Advisor
P: 2,751




#10
Dec1412, 10:16 AM

Emeritus
Sci Advisor
HW Helper
Thanks
PF Gold
P: 6,553

xl = xl is redundant



#11
Dec1412, 07:53 PM

P: 126

just give me one example and i'll do it for the rest of the statements. Thanks. I really don't have any idea. 


#12
Dec1512, 12:25 PM

Mentor
P: 21,311

You're doing the same thing later in your program where you set xu = xu. What is your purpose in doing this? 


#13
Dec1512, 05:05 PM

P: 126

I need to put in codes the conditions given.



#14
Dec1512, 05:30 PM

Mentor
P: 21,311

x_{L}  Lower (left) endpoint of an interval x_{M}  Midpoint of an interval x_{U}  Upper (right) endpoint of an interval a) If f(x_{L})*f(x_{M}) < 0, the graph of the function crosses the xaxis somewhere between x_{L} and x_{M}, so the root you're looking for must be in the left half of the original interval. If so, USE THE SAME VALUE FOR x_{L} (i.e., don't change x_{L}) but reset x_{U} to x_{M}. Your code should NOT include x_{L} = x_{L}. b) If f(x_{L})*f(x_{M}) > 0, the graph of the function does not cross the xaxis between x_{L} and x_{M}, so we should look in the other half of the interval  in [x_{M}, x_{U}]. If so, USE THE SAME VALUE FOR x_{U} (i.e., don't change x_{U}), but reset x_{L} to x_{M}. Your code should NOT include x_{U} = x_{U}. At each step for a) or b), we are shortening the interval by half its length, so that we eventually find the root. c) If f(x_{L})*f(x_{M}) = 0 then either f(x_{L}) = 0 or f(x_{M}). There's probably an assumption that f(x_{L}) ≠ 0 and f(x_{U}) ≠ 0, but you didn't show it in the attachment you posted. 


#15
Dec1512, 05:45 PM

P: 126

Yes, I understand that,, I just dont know how to put it in codes. i'll work on all your hints now. Thanks :)



#16
Dec1512, 08:01 PM

Mentor
P: 7,320

Perhaps you could work through several iterations by hand. Once you get an understanding of how the algorithm works you can then write the code.
Step 1. Is there a root on the interval? Step 2. Find the midpoint. step 3. Find the half that has a root. Step 4. Repeat. 


#17
Dec1512, 08:04 PM

P: 126

I did that already. Im not getting the same answer with the the program so I know there's something wrong. Thanks for the help guys. Appreciate it.



#18
Dec1512, 10:54 PM

Sci Advisor
P: 2,751




Register to reply 
Related Discussions  
Bisection method in c++  Engineering, Comp Sci, & Technology Homework  2  
FORTRAN Help: Bisection Method & Roots of Functions  Engineering, Comp Sci, & Technology Homework  3  
Differential equations, euler's method and bisection method  Calculus & Beyond Homework  3  
Bisection method by c  Programming & Computer Science  10  
Bisection Method  Programming & Computer Science  2 