#LET OP

bewerking=bewerking3.proc

!if $taal=nl
    nivo_title=Bepaal de co&ouml;rdinaten van de Top 
    de_top=het toppunt is
!else
    nivo_title=Determine the "Top-co&ouml;rdinates"
    de_top=the top is
!endif
R=$graad

#functie=(Cx -A)(x+B)= Cx^2 +xCB -xA -AB = Cx^2 +x(CB-A) -AB
#a= C
#b= CB-A
#c= AB

FF=!shuffle f,g,h,k,p,w

!for n=1 to $aantal_sommen
    !if $graad = 0
	R=$n
    !endif    
    !if $R = 1 
	A=!randitem 1,2,3,-1,-2,-3
	B=!randitem 1,2,3,-1,-2,-3
	C=!randitem 1,-1
    !endif
    !if $R = 2  
	A=!randitem 4,5,6,7,8,-1,-2,-3
	B=!randitem 1,2,3,-4,-5,-6,-7,-8
	C=!randitem 1,-1
    !endif
    !if $R = 3
	A=!randitem -1,-2,-3,-4,-5,-6,-7,-8,1,2,3,4,5,6,7,8
	B=!randitem -1,-2,-3,-4,-5,-6,-7,-8,1,2,3,4,5,6,7,8
	C=!randitem -2,-3,-4,2,3,4
    !endif
    !if $R >3 
	A=!randitem -1,-2,-3,-4,-5,-6,-7,-8,1,2,3,4,5,6,7,8
	B=!randitem -1,-2,-3,-4,-5,-6,-7,-8,1,2,3,4,5,6,7,8
	C=!randitem -1,-2,-3,-4,-5,-6,-7,-8,1,2,3,4,5,6,7,8
    !endif
    a=$C
    b=$[$C*$B - $A]
    c=$[$A*$B]
    S=-1*($b)/(2*$a)
    functie$n=(($C)*x - ($A))*(x + ($B))
    som$n=!texmath ($C*x - $A)*(x+$B)
    lijn$n=$[$S]
    sommen=!append line F=$(functie$n) to $sommen
    sommen=!append line top=$S to $sommen 
    sommen=!append line subst(F,x,top) to $sommen
    sommen=!append line printtex(F) to $sommen
    sommen=!append line printtex(top) to $sommen
    sommen=!append line printtex(subst(F,x,top)) to $sommen
!next n        
    
SOMMEN=!exec pari $sommen

r=1
!for n=1 to $aantal_sommen
    keuze=!randitem 1,2
    X=!line $[$r+1] of $SOMMEN
    Y=!line $[$r+2] of $SOMMEN
    Xtex=!line $[$r+4] of $SOMMEN
    Ytex=!line $[$r+5] of $SOMMEN
    goed$n=\left( $Xtex : $Ytex \right)
    GOED$n=$X,$Y
    Goed$n= $de_top  ($X:$Y)
    !if $keuze=1
	som$n=!line $[$r+3] of $SOMMEN
	som$n=y \,\, = $(som$n)
    !else
	F=!item $n of $FF
	som$n=$F\left( x \right) = $(som$n)
    !endif
    !endif	
    r=$[$r + 6]    
!next n

!if $PLAATJE=1
    !for n=1 to $aantal_sommen
	plaatje$n=\
	transparent white\
	xrange -10,10\
	yrange -100,100\
	vline 0,0,blue\
	hline 0,0,blue\
	linewidth 2\
	dvline $(lijn$n),0,red\
	curve green,$(functie$n)\
	linewidth 6\
	point $(GOED$n),red
    !next n
!endif

