cu-numcomp / numcomp-class-spring19

CSCI-3656 Numerical Computation (Spring 2019)
BSD 2-Clause "Simplified" License
7 stars 21 forks source link

Homework 0: division by zero #3

Closed 1s0m0rph closed 5 years ago

1s0m0rph commented 5 years ago

I've found a function that should work for the first question, but the tests don't pass because they run into a division by zero (the function I used is completely flat at x=1, that is, f'(1) = 0). They don't pass, though, because a Python error gets in the way.

try:
    x -= fx / dfx
except FloatingPointError:
    break

The line that throws the error is, quite clearly, the second one listed here. The way the code is written, it seems to me like this try/except block was put there to catch divisions by zero. However, when this happens Python throws a ZeroDivisionError and not a FloatingPointError. From what I can tell FloatingPointError only ever gets thrown if it's explicitly been enabled (https://docs.python.org/3.6/library/fpectl.html#fpectl.FloatingPointError) after turnon_sigfpe() is executed. If that line is executed it looks like Python should throw the error this code seems to be expecting, but otherwise it gives a ZeroDivisionError.

Just wanted to know if this was intended so I can look elsewhere for a solution to this problem.

jedbrown commented 5 years ago

Please think about what strictly monotonically increasing means.

1s0m0rph commented 5 years ago

Is that f'(x) has to be greater than zero a part of the definition? I don't see why that's necessary for something to be strictly monotonically increasing.

jedbrown commented 5 years ago

Please reread the definition in the notebook immediately above the cell you're working on or consult another resource such as https://en.wikipedia.org/wiki/Monotonic_function.

1s0m0rph commented 5 years ago

That's what I was referring to. What I don't see is why a differentiable function that is strictly increasing must have its derivative be greater than zero for all x. x^3 is, under that assumption, not strictly increasing. Wouldn't that imply there exists some real a and b such that a < b and a^3 >= b^3? Unless, of course, the derivative being greater than zero is a requirement for a differentiable function to be strictly increasing.

Edit: Got continuous and differentiable mixed up; also forgot a '^3'

jedbrown commented 5 years ago

Ah, I get your point about that implication when the definition does not involve a limit, but please work with f'(x) > 0 for this question.

1s0m0rph commented 5 years ago

Okay, awesome. I'll find a different function then. Thanks for the clarification!