I have added another coefficient (5 in all), permutated them and shown the resulting graphs.(120 in total)
There is a strange kind of pattern (press space or escape)
Code: Select all
screen 20,32
#include "string.bi"
dim as double minx,maxx,miny,maxy,x
dim as integer xres,yres
screeninfo xres,yres
minx=-5
maxx=5
miny=-20
maxy=20
#macro sketch(_function,colour)
var cc=colour
For x =minx To maxx Step (maxx-minx)/1000
Dim As Double x1=(xres)*(x-minx)/(maxx-minx)
Dim As Double y1=(yres)*(_function-maxy)/(miny-maxy)
if x=minx then Pset(x1,y1),cc else line -(x1,y1),cc
Next x
#endmacro
#macro axis(colour)
line(0,(yres-(miny/(miny-maxy))*yres))-(xres,(yres-(miny/(miny-maxy))*yres)),colour 'x axis
line(((minx/(minx-maxx))*xres),0)-(((minx/(minx-maxx))*xres),yres),colour 'y axis
draw string(0,(yres-(miny/(miny-maxy))*yres)),format(minx),colour
draw string(xres-8-8*(len(format((maxx)))),(yres-(miny/(miny-maxy))*yres)),format(maxx),colour
draw string (xres/2,0),format(maxy),colour
draw string (xres/2,yres-16),format(miny),colour
#endmacro
Sub Permutate(s As String,perm() as string,OptionalStop as string="")
Dim As Integer p,i,j,result
Dim As String s2=s
Redim perm(0)
For p1 As Integer =0 To Len(s2)-2
For p2 As Integer =p1 + 1 To Len(s2)-1
If s2[p1]>s2[p2] Then Swap s2[p1],s2[p2]
Next p2
Next p1
Do
p=p+1
redim preserve perm(1 to p)
perm(p)=s2
if s2=OptionalStop then goto skip
Do
For i=Len(s2)-2 To 0 Step -1
If s2[i] <s2[i+1] Then Exit For
Next
If i <0 Then Result=0:Exit Do
j =Len(s2)-1
While s2[j] <= s2[i]: j -=1 : Wend
Swap s2[i], s2[j]
i +=1
j =Len(s2)-1
While i <j
Swap s2[i], s2[j]
i +=1
j -=1
Wend
result=-1:Exit Do
Loop
Loop Until result=0
skip:
Redim Preserve perm(1 To p)
End Sub
Function polyeval(Coefficients() As Double,Byval x As Double) As Double
Dim As Double acc
For i As Long=Ubound(Coefficients) To Lbound(Coefficients) Step -1
acc=acc*x+Coefficients(i)
Next i
Return acc
End Function
redim shared as string p()
permutate("12345",p()) 'get 120 different states
'set a reference polynomial.
do
cls
randomize
#define dd(d1,d2) rnd*d1-rnd*d2
dim as double D(1 to 5)
d(1)=dd(5,8)
d(2)=dd(5,5)
d(3)=dd(3,2)
d(4)=dd(1,1)
d(5)=dd(1,1)
'======================
dim as double B(1 to 5) 'working polynomial
windowtitle "Coefficients " &d(1) &" " &d(2) &" " &d(3) &" " &d(4) &" " &d(5)
axis(rgb(200,200,200))
for z as long=lbound(p) to ubound(p)
for z2 as long=1 to len(p(z))
b(valint(mid(p(z),z2,1)))=d(z2)
next z2
sketch(polyeval(B(),x),rgb(rnd*255,rnd*255,rnd*255))
next z
sleep
if inkey=chr(27) then end
loop
sleep