#LET OP
# nivo's niet synchroon met bewerking.proc's
#rotzakken....
bewerking=bewerking7.proc

!if $taal=nl
    nivo_title=Bepaal de nulpunten  
    geen=er zijn geen wortels 
    twee=de twee wortels zijn 
    en=en
    ene=de ene wortel is 
!else
    nivo_title=Determine the "square roots"
    geen=there are no "square roots"
    twee=the two "square roots" are
    en=and
    ene=the only "square root" 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
    F=!item $n of $FF
    !if $graad = 0
	R=$n
    !endif    
    !if $R = 1
	a=!randitem -1,1
	b=!randitem -5,-4,-3,-2,-1,1,2,3,4,5
	c=!randitem -10,-8,-6,-4,-2,-1,1,2,4,6,8,10 
    !endif
    !if $R = 2  
	a=!randitem -1,1
	b=!randitem -5,-4,-3,-2,-1,1,2,3,4,5
	c=!randitem -10,-8,-6,-4,-2,-1,1,2,4,6,8,10 
    !endif
    !if $R = 3
	a=!randitem -1,1
	b=!randitem -5,-4,-3,-2,-1,1,2,3,4,5
	c=!randitem -10,-8,-6,-4,-2,-1,1,2,4,6,8,10 
    !endif
    !if $R >3 
	a=!randitem -1,1
	b=!randitem -5,-4,-3,-2,-1,1,2,3,4,5
	c=!randitem -10,-8,-6,-4,-2,-1,1,2,4,6,8,10 
    !endif
    functie$n=($a)*x^2 + ($b)*x + ($c)
    
    !if $[$b*$b - 4*($a)*($c)] >= 0
	X1=(-1*$b + sqrt($b*$b - 4*($a)*($c)))/(2*($a)) 
	X2=(-1*$b - sqrt($b*$b - 4*($a)*($c)))/(2*($a)) 
	sommen=!append line expand($X1); to $sommen
	sommen=!append line expand($X2); to $sommen
	!if $[$b*$b - 4*($a)*($c)] > 0
	    extra$n=2
	!else
	    extra$n=1
	!endif    
    !else
	Goed$n=$geen
	GOED$n=geen_wortels
	goed$n=\rightarrow \,\,\, \nexists
	extra$n=0
    !endif	
!next n        
    
SOMMEN=!exec maxima $sommen

r=1
!for n=1 to $aantal_sommen
    !if $(extra$n)>0
	X1=!line $[$r] of $SOMMEN
	X2=!line $[$r+1] of $SOMMEN
	X1tex=!texmath $X1
	X2tex=!texmath $X2
	!if $(extra$n)=2
	    goed$n= \left\{ \begin{array}{c}x_{1}= $X1tex\\ x_{2}= $X2tex\end{array}\right.
	    GOED$n=$X1,$X2
	    punten$n=points red,$[$X1],0,$[$X2],0
	    #Goed$n=x=$X1  x=$X2  
	    Goed$n=$twee  x1=$X1 $en x2=$X2  
	!else
	    goed$n= x = $X1tex
	    GOED$n=$X1
	    punten$n=points red,$[$X1],0,$[$X1],0
	    Goed$n=$ene x=$X1  
	!endif
	r=$[$r + 2]    
    !endif
    ff=!texmath $(functie$n)
    keuze=!randitem 1,2
    !if $keuze=1
	F=!item $n of $FF
	som$n=$F\left( x \right)=$ff
    !else
	som$n=y \,\, = $ff
    !endif	
!next n

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