You can use this method with any of the built-in regression commands. You need to enter as many
points as there are coefficients in the equation. For example, the CubicReg command fits the data to a
cubic polynomial with four coefficients, so you would need to enter four points.
I mentioned that the function str2var() is called by quadint(). This is str2var():
str2var(xy)
Func
©("x,y") returns {x,y}
©15oct00 dburkett@infinet.com
local s,x,y
instring(xy,",")→s ©Find comma
if s=0:return "str2var err" ©Return error string if no comma found
expr(left(xy,s-1))→x ©Get 'x' from string
expr(right(xy,dim(xy)-s))→y ©Get 'y' from string
return {x,y} ©Return list of x & y
EndFunc
[6.32] Accurate approximate solutions to quadratic equations with large coefficients
This tip shows a method to calculate the approximate roots of the quadratic equation ax
2
+ bx + c =,
when a and b are very small. In this case, calculating the roots with the 'classical' solution formula
results in less accurate roots. The classical solution is
or
x =
−b! b
2
−4ac
2a
x =
2c
−b! b
2
−4ac
These solutions result in round-off errors for small values of a and b. A better solution is
then
q =
−
1
2
b + sign
(
b
)
b
2
− 4ac
and
x1 =
q
a
x2 =
c
q
This function, quadrtic(), uses these equations.
quadrtic(aa,bb,cc)
func
©(a,b,c) in ax^2+bx+c=0
©27oct00 dburkett@infinet.com
local q
when(bb≠0,⁻(bb+sign(bb)*√(bb*bb-4*aa*cc))/2,⁻(bb+√(bb*bb-4*aa*cc))/2)→q
{q/aa,cc/q}
Endfunc
To use quadrtic(), call it with the coefficients (a,b,c). The two roots are returned as a list. For example,
quadrtic(8,-6,1)
returns {0.5,0.25}
6 - 60