q2=: (3 : 0)&((0&+) ::('invalid data type'"_))"1
 if. ([: -. (3=#) *. (0~:{.)) y do. 'Not quadratic' return. end.
 'A B C'=. y
 SQRTD=. %: (*:B)- +:^:2 A*C
 S=. SQRTD-B
 T=. -SQRTD+B
 R=. (S [`]@.(<&|) T)%+:A
 R , C % R * A
)

   (quad,:q2)_1e_10 2 0.0001  NB. quad is RDM monadic p. solution
2e10 _5e_5
2e10 _5e_5

Swapping left and right causes

   (quad,:|.@qbad)_1e_10 2 0.0001
      2e10       _5e_5
2.04709e10 _4.88498e_5




On 11/07/2015 07:00 AM, [email protected] wrote:
Date: Fri, 6 Nov 2015 17:18:34 -0600
From: Kip Murray<[email protected]>
To:"[email protected]"  <[email protected]>
Subject: [Jprogramming] Quadratic formula
Message-ID:
        <CAOfWorjaCT8UZTKi-+Z342WAu+YKg9MRNQFSJKXLqgB+=pd...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

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.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to