I've been programming an inflection point solver in Nspire BASIC, and my code seems to have an odd bug in it. If x^4+cx+d, where c and d are constants (ex. x^4+3x), is entered, the program spits out an error of nsolve not having an equation in the first argument, and I can't figure out why.
Define inflect(ex)=
Func
:Local ansx,di2,di3,ex,i,out
:derivative(ex,x,2)→di2
:derivative(di2,x)→di3
:ansx:=10^(99)
:out:={}
:For i,1,10
: nSolve(di2=0,x=ansx,−10^(99),ansx-10^(−7))→ansx
: If ansx="No solution found" Then
: Exit
: EndIf
: If 0≠di3|x=ansx Then
: out[2*i-1]:=ansx
: out[2*i]:=ex|x=ansx
: EndIf
:EndFor
:Return out
:EndFunc
ex is the expression entered, di2 and di3 are the second and third derivatives respectively, out is the output, ansx is the last x value found, and i is the for loop variable.
Also, any suggestions on how to make my code more efficient and such would be nice.
EDIT: Attached program below.