You are right Linda, the code I wrote works only when both roots are real because + means conjugate in J. For a more general verb one can replace + by ] in the definition of qr; that is,
qr=. (-@:B + (] , -) @:%:@:(*:@:B - 4 * A * C)) % 2 * A So, quad 1 0 1 0j1 0j_1 When (C ~: 0), I prefer the formula, qr=. _2 * C % (B + (] , -) o %:@:(*: o B - 4 * A * C)) because it also provides the solution to the linear case ((A = 0) *. (B ~: 0) ); more on that later. On Fri, Nov 27, 2015 at 9:34 PM, Linda A Alvord <[email protected]> wrote: > Jose, I went back to look at your code and I think the result for 1 0 1 > should be: > > 0j1 0j_1 > > I was still thinking about getting "not quadratic" in the single line. > > > Linda > > -----Original Message----- > From: [email protected] [mailto: > [email protected]] On Behalf Of Jose Mario Quintana > Sent: Monday, November 9, 2015 12:35 PM > To: Programming forum > Subject: Re: [Jprogramming] Quadratic formula > > Tacitly... > > (A=. 0&{) (B=. 1&{) (C=. 2&{) > 0&{ 1&{ 2&{ > > qr=. (-@:B + (+ , -) @:%:@:(*:@:B - 4 * A * C)) % 2 * A > quad=. qr`('Not quadratic'"_)@.(0 -: A) f. > > quad 2 _8 6 > 3 1 > quad 0 _8 6 > Not quadratic > > > On Mon, Nov 9, 2015 at 2:26 AM, Don Kelly <[email protected]> wrote: > > > If you assume the form is ax^2 +bx +c =0 then all you have to do is > > check for a=0 0=0{ a b c is true so not quadratic and flag it if > > true > > > > Don Kelly > > > > > > On 11/6/2015 3:18 PM, Kip Murray wrote: > > > >> Most of us have heard of the quadratic formula > >> > >> x = ( -b +or- %: (b^2 - 4ac) )/2a (roughly standard math notation) > >> > >> for solving ax^2 + bx + c = 0 for x . > >> > >> Your mission, should you decide to accept it, is to write a verb quad > >> that takes > >> vector a,b,c as argument, says “Not quadratic” if a is 0 , and > >> otherwise uses the quadratic formula to find the values of x, > >> reporting them in a vector. > >> > >> quad 2 _8 6 > >> 3 1 > >> > >> quad 0 _8 6 > >> Not quadratic > >> > >> --Kip Murray > >> > >> > >> > >> > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
