Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
implement the algorithms for the bisection and false-point variant discussed from the 04-Lecture-part-a notebook to approximate the  𝑟  that makes the centered-difference approximation of  𝑑𝑆/𝑑𝑟=0  (use  ℎ=0.001  when calling this finite-difference function). Use an interval of  (0,40]  and a tolerance of  0.01  in both algorithms. Comment on the number of times  𝑆  must be evaluated to achieve the desired tolerance for each algorithm (hint: look at the total number of iterations and check how many times  𝑆  must be evaluated by the finite-different function). Compare this to the brute-force approach.


What I have tried:

def for_diff(f,x=0,h=.1):
    '''
    Computes a forward difference approximation to the derivative of f at
    x using a step-size of h.
    
    >>> for_diff(lambda x : 5)
    0.0
    
    >>> for_diff(lambda x : 5*x)
    5
    '''
    deriv=(f(x+h)-f(x))/h
    return deriv

def back_diff(f,x=0,h=.1):
    deriv=(f(x)-f(x-h))/h
    return deriv

def cent_diff(f,x=0,h=.1):
    deriv=(f(x+h)-f(x-h))/(2*h)
    return deriv
Posted
Updated 5-Oct-20 19:59pm

1 solution

We can't help: we don't have access to your "04-Lecture-part-a" document it refers to, and it's your homework anyway - so your tutor is looking for your ideas, not mine!

Start with that document: read it carefully to find out what the algorithms your homework is referring to are and how they work. Then write two methods: one which implements each algorithm and pass them the same data. When they work properly, write a brute-force approach method, and hand it the same data. When that works, you can start comparing them on the basis of results, execution time, whatever your tutor needs you to do.

But we aren't going to do it all for you, even if we had access to the algorithms and sample data!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900