The original question assumes that a.b c are given for the quadratic "
ax^2 =BX=c =0"
and doesn't indicate that the classic quadratic formula is to be used
but all that is wanted is a response "not quadratic" or the roots of
the quadratic. Let's use the capabilitiy of J.
We could use 'if' etc but this seems to do the trick
quad=:13 :'(0=0{y){ ((>1{p.@:|.y);'' notquadratic'')'
OR quadtacit=: (0 = 0 { ]) { ' notquadratic' ;~ [: > 1 { p.@:|.
quad 0 _8 6
┌────────┐
│ not quadratic│
└────────┘
quad 2 _8 6
┌──┐
│3 1 │
└──┘
quad 1 2 3
┌───────────────┐
│_1j1.41421 _1j_1.41421 │
└───────────────┘
Don Kelly
On 11/11/2015 4:30 PM, Jose Mario Quintana wrote:
It is unfortunate that qr does not produce a solution for the linear case
(when A is 0). However,
qr=. _2 * C % (B + (+ , -) @:%:@:(*:@:B - 4 * A * C))
does,
qr 0 _8 6
__ 0.75
qr 2 _8 6
3 1
On Mon, Nov 9, 2015 at 12:34 PM, Jose Mario Quintana <
[email protected]> wrote:
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