Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can any one please help with this code. This is my first time using python and I

ID: 3623415 • Letter: C

Question

Can any one please help with this code. This is my first time using python and I need help figuring what am I doing wrong!

so we were asked to use newton's method for a specific function with tolerance .00001 and initial guess=20 this is what I wrote:

>>>def f(t):
return (math.log10(math.cosh(t*0.1828665)))/.00341
>>>def deriv(t):
return (0.1828665 * math.sinh(0.1828665 * t))/math.cosh(0.1828665 * t)
>>>x=1
>>>ti=20
>>>while x<21:
getcontext().prec=4
t= ti - f(ti)/deriv(ti)
print 't',x, '=',t
print 'f(t',x,')','=',f(t)
print 'abs(f(t',x,'))=',abs(f(t))
if abs(t)<=.00001:
print "solution converge"
break
x=x+1
ti=t

but this is what I keep getting

t 2 = 258256.106786
f(t 2 ) =

Traceback (most recent call last):
File "<pyshell#163>", line 5, in <module>
print 'f(t',x,')','=',f(t)
File "<pyshell#159>", line 3, in f
return ((math.log10(math.cosh(t*0.1828665)))/.00341)
OverflowError: math range error

can any one tell what am I doing wrong? help fix this program pleas!

Explanation / Answer

try on your on?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote