Author Topic: Power function  (Read 9411 times)

0 Members and 1 Guest are viewing this topic.

Offline eoredson

  • Newbie
  • Posts: 55
  • Let the Farce be with you!
    • View Profile
    • Oredson QB45 Files At Filegate
Re: Power function
« Reply #15 on: July 28, 2018, 11:01:44 pm »
This attached file (by STxAxTIC) is called sxmath with tweaks for powers and fractional powers to any digit:

Erik.
* sxmath.zip (Filesize: 5.96 KB, Downloads: 225)

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Power function
« Reply #16 on: July 29, 2018, 09:08:14 am »
Say, thanks for the plug! I'll have to drag that project back out into public display one of these days...
You're not done when it works, you're done when it's right.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Power function
« Reply #17 on: July 29, 2018, 11:21:29 pm »
series experiment

Code: QB64: [Select]
  1. deflng a-z
  2. screen _newimage(800,600,12)
  3.  
  4.  
  5.         t = t + 0.1
  6.         cls
  7.         for xx=1 to 800
  8.                 x = 5*xx/800
  9.                 y = x^t
  10.                 yy = y
  11.                 pset (xx, 600-yy), 7
  12.  
  13.                 y = ppow#(x, t, 2)
  14.                 yy = y
  15.                 pset (xx, 600-yy), 14
  16.  
  17.                 y = ppow#(x, t, 3)
  18.                 yy = y
  19.                 pset (xx, 600-yy), 12
  20.  
  21.                 y = ppow#(x, t, 4)
  22.                 yy = y
  23.                 pset (xx, 600-yy), 10
  24.  
  25.                 y = ppow#(x, t, 5)
  26.                 yy = y
  27.                 pset (xx, 600-yy), 11
  28.         next
  29.         color 7:locate 1,1:?"x^"+ltrim$(str$(t))
  30.         color 14:locate 2,1:?"n=2"
  31.         color 12:locate 3,1:?"n=3"
  32.         color 10:locate 4,1:?"n=4"
  33.         color 11:locate 5,1:?"n=5"
  34.         if t>10 then t=0
  35.         _display
  36.         _limit 10
  37.  
  38. function ppow#(c as double, x as double, n)
  39.         dim cc as double, xx as double, p as double
  40.         cc = exp(c*log(c))
  41.         p = 1
  42.         xx = 1
  43.         for i=1 to n
  44.                 xx = xx*log(c)*(x-c)/fact(i)
  45.                 p = p + xx
  46.         next
  47.         ppow# = cc*p
  48.  
  49. function fact(n)
  50.         fact = 1
  51.         for i=0 to n-1
  52.                 fact = fact*(n-i)
  53.         next
  54.