Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
derivatives
#1
I am trying to use a specific formula that sort of uses it self over and over, been trying to figue it out on my own please help me. Thank you
 import math
def main():
   for i in range(20):
      x0 = 0.375
      x0 = NR(x0)
   print(format(x0, '.3f'))
def NR(x0):
   fx = int(x0**2 -3*x0 +1)
   fxp = 2*x0 - 3
   f = x0 - fx/fxp
   f = x0         
   print('x:','\t','\t','\t',format(f,'.3f'))
   return '\t','\t','\t',x0
   #print('\n','Spread sheet completed!')
main()
results:
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
Traceback (most recent call last):
  File "mathe project.py", line 25, in <module>
    main()
  File "mathe project.py", line 16, in main
    print(format(x0, '.3f'))
TypeError: unsupported format string passed to tuple.__format__
Reply
#2
I am trying to use a specific formula that sort of uses it self over and over, been trying to figue it out on my own please help me. Thank you
import math
def main():
   for i in range(20):
      x0 = 0.375
      x0 = NR(x0)
   print(format(x0, '.3f'))
def NR(x0):
   fx = int(x0**2 -3*x0 +1)
   fxp = 2*x0 - 3
   f = x0 - fx/fxp
   f = x0         
   print('x:','\t','\t','\t',format(f,'.3f'))
   return '\t','\t','\t',x0
main()
the results suppose to giving be a list of using x0 in the formula f then the results of f back in to the formula f as x0 in other words f = x0 after each cycle but my results are

results:
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
x: 	 	 	 0.375
Traceback (most recent call last):
  File "mathe project.py", line 24, in <module>
    main()
  File "mathe project.py", line 16, in main
    print(format(x0, '.3f'))
TypeError: unsupported format string passed to tuple.__format__
please help me thank you
Reply
#3
Duplicate thread. Merged ... Against the rules, please don't post duplicate threads
Reply
#4
Sorry bbout that but still needs help
Reply
#5
(Mar-19-2018, 03:02 PM)kc4566 Wrote:
def main():
   for i in range(20):
      x0 = 0.375
      x0 = NR(x0)
If you want x0 to change each iteration, then stop resetting it to 0.375 with each iteration.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020