n=$teller
!if $taal=nl
    nivo_title=Diverse vergelijkingen oplossen.
    !if $KANNIET=1
	extratekst=<br><small>Bij g&eacute;&eacute;n oplossing, vul in : <em>geen oplossing</em>of iets dergelijks</small>
    !else
	extratekst=<br>
    !endif
    somtekst$n=Los de onderstaande vergelijking op:$extratekst
    antwoord$n=We werken de vergelijking eerst om in de "nul-vorm", <br>\
    daarna is het een gewone vierkantsvergelijking die we gemakkelijk kunnen oplossen...<br>
    en=en
    no_roots=geen wortels
    raakpunt=een raakpunt
!else
    nivo_title=Solve the equation.
    !if $KANNIET=1
	extratekst=<br><small>if there is no real solution, fill in : <em>no roots</em> or something similar</small>
    !else
	extratekst=<br>
    !endif
    somtekst$n=Solve the next equation:$extratekst
    antwoord$n=We first rewrite the equation in the "null-form",<br>\
    after that it's a normal and easy to solve equation...<br>
    en=and
    no_roots=no roots
    raakpunt=a single root 
!endif

bewerking=bewerking1.proc
kleuren=red,blue,green,orange,purple
kleuren=!shuffle $kleuren
color1=!item 1 of $kleuren
color2=!item 2 of $kleuren

a=!randitem -3,-2,-1,2,3,4
b=!randitem -9,-8,-7,-6,-5,-4,-3,-2,-1,2,3,4,5,6,7,8,9
c=!randitem -9,-8,-7,-6,-5,-4,-3,-2,-1,2,3,4,5,6,7,8,9
d=!randitem -9,-8,-7,-6,-5,-4,-3,-2,-1,2,3,4,5,6,7,8,9
e=!randitem -9,-8,-7,-6,-5,-4,-3,-2,-1,2,3,4,5,6,7,8,9
f=!randitem -3,-2,1,-1,2,3
#type: ax^2+bx+c=0
D=$[($b)*($b) - 4*($a)*($c)]
!if $D<0
    !if $KANNIET=1
	kanniet$n=1
    !else
	kanniet$n=0
	c=$[-1*($c)]
	D=$[($b)*($b) - 4*($a)*($c)]
	!goto PRUTWERK
    !endif	
!else
    :PRUTWERK    
    kanniet$n=0
    DD=$[sqrt($D)]
    !if . isin $DD
	X1=(-1*($b) - sqrt($D))/($[2*($a)])
    	X2=(-1*($b) + sqrt($D))/($[2*($a)])
    	!if $afrondingsfactor !=0
	    x1=$[(round(($X1)*$afrondingsfactor))/$afrondingsfactor]
	    x2=$[(round(($X2)*$afrondingsfactor))/$afrondingsfactor]
	    X1=$x1
	    X2=$x2
	!else
	    XX=!exec maxima $X1;\
	    $X2;
	    TEST=$XX
	    X1=!line 1 of $XX
	    X2=!line 2 of $XX 
	    x1=!texmath $X1
	    x2=!texmath $X2
	!endif
    !else
	XX=!exec pari (-1*($b)-(sqrt($D)))/(2*($a))\
	(-1*($b)+(sqrt($D)))/(2*($a))\
	printtex( (-1*$b-sqrt($D))/(2*$a))\
	printtex( (-1*$b+sqrt($D))/(2*$a))    
	
	X1=!line 1 of $XX
    	X2=!line 2 of $XX
    	x1=!line 3 of $XX
    	x2=!line 4 of $XX
    !endif
!endif

!if $graad=0
    R=$teller
!else
    R=$graad
!endif
        
!if $R=1
    curve1=$a*x^2 + $b*x+ $c
    curve2=hline 0,0,$color2
    vraag=!exec pari printtex($curve1)
    vraag= $vraag \,\,\,=\,\,0
    Y1=0
    Y2=0
    !goto KLAAR
!endif
!if $R=2
    p=$[$b+$d]
    q=$[$c+$e]
    curve1=$a*x^2 + $p*x + $q
    curve2=curve $color2,$d*x+$e
    tst=$d*x+$e
    vragen=!exec pari printtex($curve1)\
    printtex(($d)*x+($e))
    vraag1=!line 1 of $vragen
    vraag2=!line 2 of $vragen
    vraag= $vraag1 \,\,\,=\,\, $vraag2
    Y1=$[$d*$X1+$e]
    Y2=$[$d*$X2+$e]
    !goto KLAAR
!endif
!if $R=3
    r=$[$a+$f]
    p=$[$b+$d]
    q=$[$c+$e]
    curve1=$q + $p*x + $r*x^2
    curve2=curve $color2,$f*x^2+$d*x+$e
    tst=$f*x^2+$d*x+$e
    vragen=!exec pari printtex($curve1)\
    printtex($f*x^2+$d*x+$e)
    vraag1=!line 1 of $vragen
    vraag2=!line 2 of $vragen
    vraag= $vraag1 \,\,\,=\,\, $vraag2
    Y1=$[$q + $p*$X1 + $r*$X1*$X1]
    Y2=$[$q + $p*$X2 + $r*$X2*$X2]
    !goto KLAAR
!endif
!if $R >3
    d=!randitem 2,3,4,5,6,7,8,9
    !if $b=$[-1*$d] 
	d=$[$d+1]
    !endif	
    tot=!exec pari e=((($d)^2)/2)\
    q=$c+e\
    p=$b+$d\
    r=$a+1/2\
    printtex(e)\
    printtex(q)\
    printtex(p)\
    printtex( (r/p)*x)
    
    e=!line 1 of $tot
    q=!line 2 of $tot
    p=!line 3 of $tot
    r=!line 4 of $tot
    ee=!line 5 of $tot
    qq=!line 6 of $tot
    pp=!line 7 of $tot
    breuk=!line 8 of $tot
    
    
#	type: ax^2+bx+c=0
#	D=$[($b)*($b) - 4*($a)*($c)]

#	q+px+rx^2=0.5*x^2+dx+e
#	(r-0,5)x^2+(p-d)x+q-e=0
#	(r-0,5)x^2 + (b+d-d)x + c+e-e=0
#	a=r-0.5-> r=a+0.5
#       b=b+d-d
# 	c=q-e -> c=c+e -e   
#	==> ax^2+bx+c=0
#	q + p*x + r*x^2 = 0.5*x^2 + d*x +e KLOPT !!! want dit is ==> ax^2+bx+c=0

# 
# breuk erin (x+d)^2/2 = (x^2+2dx+d^2)/2  = 0.5x^2+dx+ 0.5d^2 
# 			 q+px+rx^2        = 0.5x^2+dx+ e
# dus als e=0.5*d^2 klopt dit ook nog steeds => q + p*x + r*x^2 = (x+d)^2/2
# KLOPT
# ook linkerlid ingewikkeld lijken type px(1+qx)
# q + p*x + r*x^2 => q+px(1+(r/p)*x)
# dus vraag1=q+px(1+(r/p)*x)
# dus vraag2=(x+d)^2/2
# Als e=0.5d^2

	curve1=$q + $p*x + $r*x^2
	curve2=curve $color2,0.5*x^2 + $d*x +$e
	tst=0.5*x^2 + $d*x +$e
#	vraag1=$qq+$pp\cdot x \left( 1 + \frac{$rr}{$pp} \cdot x \right)
	vraag1=$qq + $pp \cdot x \left( 1 + $breuk \right)
	vraag2=\frac{\left( x + $d \right)^{2}}{2}    
    vraag= $vraag1 \,\,\,=\,\, $vraag2
    vraag=!replace internal + - by - in $vraag    
    vraag=!replace internal - - by + in $vraag    
    Y1=$[$q + $p*$X1 + $r*$X1*$X1]
    Y2=$[$q + $p*$X2 + $r*$X2*$X2]
!endif

#OPMERKING=$curve1,$tst
#OPMERKING=!replace internal ^ by ** in $OPMERKING
#OPMERKING=plot $OPMERKING <br>\
#solve($curve1=$tst,x); dit is de onderliggende vraag<br>\
# solve($q + ($p)*x + ($r)*x^2 = ((x+$d)^2)/2,x); rechterlid moeilijker<br>\
# solve($q+($p)*x*(1+($r/$p)*x)=(x+($d))^2/2,x);<br>

:KLAAR

#type: ax^2+bx+c=0
!if $[$D]=0
    nulpunten=1
    GOED$n=$X1
    wortels$n=\overrightarrow{een \,\,raakpunt\,\,} x_1 = $x1
    !if $wims_user=supervisor
    	G$n= x=$X1 $raakpunt
    !endif
    punten=point $X1,$Y1,red
!else
    !if $[$D]>0
	nulpunten=2
	GOED$n=$X1,$X2
	wortels$n=\left\{ \begin{array}{c} x_1 = $x1\\ x_2 = $x2  \end{array}\right.
	!if $wims_user=supervisor
    	    G$n= x1=$X1 $en x2=$X2
	!endif
    	punten=point $X1,$Y1,red\
    	point $X2,$Y2,red
    !else
	nulpunten=0
	kanniet$n=1
	wortels$n=\overrightarrow{geen \,\,oplossingen\,\,dus } \,\,\,\, x_1 \in \varnothing
	!if $wims_user=supervisor
    	    G$n= $no_roots
	!endif	    
	punten=$empty
    !endif	
!endif

opgave$n=$vraag 
!readproc nivo/plaatje$nivo.proc


#!if $R <0
#    q=$[$c+$e]
#    p=$[$b+$d]
#    !if $p=0
#	totaal=!exec pari $a+1/2\
#	printtex(($d^2)/2 - ($e))	
#	r=!line 1 of $totaal
#	ee=!line 2 of $totaal
#	curve1=$q + $p*x + $r*x^2
#	curve2=curve $color2,0.5*x^2 + $d*x +$e
#	!if $q=0
#	    vraag1=$r\cdot x^{2} 
#	!else
#	    vraag1=$r\cdot x^{2} + $q
#	!endif
#    !else
#	totaal=!exec pari ZZZ=$a+1/2\
#	printtex(-1*($d^2)/2+($e))\
#	printtex((ZZZ)/$p)    	
#	r=!line 1 of $totaal
#	ee=!line 2 of $totaal
#	rr=!line 3 of $totaal
#	curve1=$q + $p*x + $r*x^2
#	curve2=curve $color2,0.5*x^2 + $d*x +$e
#	tst=0.5*x^2 + $d*x +$e
#	!if $q=0
#	    vraag1=$p\cdot x\left(1 + $rr \cdot x\right)
#	!else
#	    vraag1=$q + $p\cdot x\left(1 + $rr \cdot x\right)
#	!endif
#    !endif
#    !if $ee = 0
#	vraag2=\frac{\left(x + $d \right)^2}{2}    
#    !else
#	vraag2=\frac{\left(x + $d \right)^2}{2} + $ee    
#    !endif
#    
#    vraag= $vraag1 \,\,\,=\,\, $vraag2
#    vraag=!replace internal + - by - in $vraag    
#    vraag=!replace internal - - by + in $vraag    
#    Y1=$[$q + $p*$X1 + $r*$X1*$X1]
#    Y2=$[$q + $p*$X2 + $r*$X2*$X2]
#!endif
#