Programmeren in TI-Basic/Vierkantsvergelijking
Uit Wikibooks
We bepalen a,b en c, de coëfficiënten van de vierkantsvergelijking ax2 + bx + c.
:Prompt A,B,C
Een eerste stap is de bepaling van de discriminant
. Er zijn drie mogelijke waarden van deze determinant:
- Groter dan nul: twee oplossingen
- Gelijk aan 0: één oplossing
- Kleiner dan nul: twee complexe oplossingen
Op deze pagina zullen we twee vierkantsvergelijkingsoplossers geven: een oplosser die enkel de reële oplossingen geeft, en een oplosser die ook de complexe oplossingen kan vinden.
- Reële oplosser
:B²-4AC→D :(-B+D)/(2A)→X :(-B-D)/(2A)→Y :Disp"De oplossingen:",X,Y
- Complexe oplosser
We moeten de rekenmachine wel eerst in "complexe modus" brengen. Eventueel kan je na de uitvoer van het programma deze instelling weer op de normale instelling zetten.
:Complex :B²-4AC→D :(-B+D)/(2A)→X :(-B-D)/(2A)→Y :Disp"De oplossingen:",X,Y
- Oplosser met mooie interface
PROGRAM:ABC
:ClrDraw
:0→S
:Prompt A,B,C
:Input "A2=?",D
:Input "B2=?",E
:Input "C2=?",F
:A-D→A
:B-E→B
:C-F→C
:ClrHome
:Disp "TEKEN:
:Disp "1 = >0
:Disp "2 = <0
:Disp "3 = =0
:Input "",T
:ClrHome
:B²-4AC→D
:Disp "D=
:Output(1,3,D
:If D<0
:Then
:If T=3
:Disp "GEEN SNIJPUNTEN
:If T=2
:Then
:If A>0
:Disp "X NOOIT <0
:If A<0
:Disp "X ALTIJD <0
:End
:If T=1
:Then
:If A>0
:Disp "X ALTIJD >0
:If A<0
:Disp "X NOOIT >0
:End
:1→S
:End
:If not(S
:Then
:(-B+√(D))/(2A→U
:(-B-√(D))/(2A→V
:ClrHome
:If T=3
:Then
:Disp "X=
:Output(1,3,U
:Disp "X=
:Output(2,3,V
:(V+U)/2→M
:Disp "MIDDEN:
:Output(3,8,M
:M→X
:AX²+BX+C→N
:If N>0
:Then
:Disp "TOP:
:Else
:Disp "DAL:
:End
:Output(4,5,N
:End
:If T=2
:Then
:If A>0
:Then
:Disp "X>
:Output(1,3,U
:Disp "X<
:Output(2,3,V
:Else
:Disp "X<
:Output(1,3,U
:Disp "X>
:Output(2,3,V
:End
:End
:If T=1
:Then
:If A>0
:Then
:Disp "X<
:Output(1,3,U
:Disp "X>
:Output(2,3,V
:Else
:Disp "X>
:Output(1,3,U
:Disp "X<
:Output(2,3,V
:End
:End
:End
:Pause
:Text(10,3,"D=",B,"²-4*",A,"*",C,"=",D
:If not(S
:Then
:Text(20,3,"X1=(-",B,"+√(",D,"))/(2*",A,")=",U
:Text(20,3,"X1=(-",B,"-√(",D,"))/(2*",A,")=",V