!set n=$teller
R=$graad
!if $graad=0
    R=$teller
!endif    

bewerking=nivo/bewerking4.proc
	
a=!randitem 2,3,4,5,6
b=!randitem 2,3,4,5,6
!if $a=$b
    b=$[$a+1]
!endif

pm=!randitem +,-
mp=!randitem +,-
keuze=!randitem 2,1
	
!if $R = 1 or $R = 2
    anders=1
    !if $R=1
	c=1
    !else
	c=!randitem 2,3,4,5,6
    !endif	
    BEREIK=!randint 1,6	
    X1=!randint $[-1*$a+1],$[$b-1]
    X2=$[$b+$BEREIK]
    !if $keuze=1
        f=$c*(x+$a)*(x-$b)
	Xmin=$[(-1*$a+$b)/2]
	Xmax=$X2
    !else
        f=-1*$c*(x+$a)*(x-$b) 
	Xmax=$[(-1*$a+$b)/2]
	Xmin=$X2
    !endif
    tot=!exec pari $f\
    printtex($f)
    functie$n=!line 1 of $tot
    totaal=!exec maxima integrate($(functie$n) ,x,$X1,$b);\
    integrate($(functie$n) ,x,$b,$X2);\
    integrate($(functie$n),x);
    G1=!line 1 of $totaal
    G2=!line 2 of $totaal 
    GOED$n=!exec pari abs($G1)+abs($G2)
    !if log isin $(GOED$n)
	GOED$n=!replace internal log by ln in $(GOED$n)
    !endif
    goed$n=!line 3 of $totaal
    goed$n=!texmath $(goed$n)
    !if $keuze=1
        goed$n= - \left [ $(goed$n) \right ]_{$X1}^{$b} + \left [ $(goed$n) \right ]_{$b}^{$X2}
    !else
        goed$n= \left [ $(goed$n) \right ]_{$X1}^{$b} - \left [ $(goed$n) \right ]_{$b}^{$X2}
    !endif
    !if $plaatje=1
	y1=!evalsubst x=$Xmin in $(functie$n)
	y2=!evalsubst x=$Xmax in $(functie$n)
	!if $y1 > $y2
    	    Y1=$y2
	    Y2=$y1
	!else
	    Y1=$y1
	    Y2=$y2
	!endif		 
	!if $Y1>0
	    Y1=-5
	!endif
	!if $Y2<0
	    Y2=5
	!endif
	xrange=$[-1*$a - 5],$[$X2+5]
	yrange=$[$Y1-5],$[$Y2+5]
        rect=rect $[-1*$a-5],$[$Y1-5],$[$X2+5],$[$Y2+5],black
        curve=curve red,$(functie$n)
    !endif
!endif

!if $R = 3
    anders=1
    BEREIK=!randint 1,5	
    X1=!randint $[-1*$a+1],-1
    X2=$[$b+$BEREIK]
    !if $keuze=1
        f=x*(x+$a)*(x-$b)
    !else
        f=x^2*(x+$a)*(x-$b) 
    !endif
    tot=!exec pari $f\
    printtex($f)
    functie$n=!line 1 of $tot
    totaal=!exec maxima integrate($(functie$n) ,x,$X1,0);\
    integrate($(functie$n) ,x,0,$b);\
    integrate($(functie$n) ,x,$b,$X2);\
    integrate($(functie$n),x);
    G1=!line 1 of $totaal
    G2=!line 2 of $totaal 
    G3=!line 3 of $totaal
    !if $keuze=1 
        GOED$n=!exec pari ($G1)-($G2)+($G3)
	mm=
    !else
        GOED$n=!exec pari ($G3)-($G1)-($G2)
	mm=-
    !endif
    !if log isin $(GOED$n)
	GOED$n=!replace internal log by ln in $(GOED$n)
    !endif
    goed$n=!line 4 of $totaal
    goed$n=!texmath $(goed$n)
    goed$n= $mm \left [ $(goed$n) \right ]_{$X1}^{0} - \left [ $(goed$n) \right ]_{0}^{$b} + \left [ $(goed$n) \right ]_{$b}^{$X2}
    !if $plaatje=1
	y1=!evalsubst x=$[$b/2] in $(functie$n)
	y2=!evalsubst x=$X2 in $(functie$n)
	!if $y1 > $y2
    	    Y1=$y2
	    Y2=$y1
	!else
	    Y1=$y1
	    Y2=$y2
	!endif		 
	!if $Y1>0
	    Y1=-5
	!endif
	!if $Y2<0
	    Y2=5
	!endif
	xrange=$[-1*$a - 5],$[$X2+5]
	yrange=$[$Y1-50],$[$Y2+5]
	curve=curve red,$(functie$n)
        rect=rect $[-1*$a-5],$[$Y1-50],$[$X2+5],$[$Y2+5],black
    !endif
!endif

!if $R > 3
    anders=1
    c=!randitem -6,-4,-2,2,4,6,8
    p=!randitem -6,-4,-2,2,4,6,8
    !if $c=$p
	c=$[-1*$c]
    !endif
    a=!randitem 1,2,3,4,5
    b=$[($c-$p-2*$a)/2]
    !if $a=$b
        a=$[$a+1]
        b=$[($c-$p-2*$a)/2]
    !endif
    !if $a > $b
        X1=$b
        X2=$a
    !else
	X1=$a
	X2=$b
    !endif		 
    d=!randitem 1,2,3,4,5,6
    q=$[2*$a*$b+$d]
    f=-1*x^2+$c*x+$d
    g=x^2+$p*x+$q
    functie1$n=$f
    functie2$n=$g
    functie$n=!exec pari ($f-($g))
    totaal=!exec maxima integrate($(functie$n) ,x,$X1,$X2);\
    integrate($(functie$n),x);
    GOED$n=!line 1 of $totaal
    goed$n=!line 2 of $totaal
    goed$n=!texmath $(goed$n)
    goed$n= \left [ $(goed$n) \right ]_{$X1}^{$X2}
    !if $plaatje=1
	y1=!evalsubst x=$[(-1*$p)/2] in $(functie2$n)
	y2=!evalsubst x=$[$c/2] in $(functie1$n)
	!if $y1 > $y2
    	    Y1=$y2
	    Y2=$y1
	!else
	    Y1=$y1
	    Y2=$y2
	!endif		 
	!if $Y1>0
	    Y1=-5
	!endif
	!if $Y2<0
	    Y2=5
	!endif
	!if $a > $b
    	    X1=$b
	    X2=$a
	!else
	    X1=$a
	    X2=$b
	!endif		 
	xrange=$[$X1-5],$[$X2+5]
	yrange=$[$Y1-5],$[$Y2+5]
        rect=rect $[$X1-5],$[$Y1-5],$[$X2+5],$[$Y2+5],black
	curve=curve red,$(functie1$n)\
	curve orange,$(functie2$n)
    !endif
!endif



!if $plaatje=1	
    plaatje$n=\
    xrange $xrange\
    yrange $yrange\
    hline 0,0,blue\
    vline 0,0,blue\
    linewidth 2\
    $curve\
    dvline $X1,0,green\
    dvline $X2,0,green\
    $rect
!endif

nivo_title=!record 3 of lang/remarks.$taal
!if $R<4
    opgave$n=$empty
    F=!htmlmath f(x) = $(functie$n)
    F=!replace internal sqrt by <font size="+1">&radic;</font> in $F
    test=!record 18 of lang/remarks.$taal
    somtekst$n=$test
!else
    FF=!texmath $(functie1$n)
    GG=!texmath $(functie2$n)
    opgave$n=\int_{$X1}^{$X2} \left( $FF - \left( $GG \right)\right) dx \rightarrow
    F=!htmlmath f(x) = $(functie1$n)
    G=!htmlmath g(x) = $(functie2$n)
    F=!replace internal sqrt by <font size="+1">&radic;</font> in $F
    test=!record 19 of lang/remarks.$taal
    somtekst$n=$test
!endif


