0

I'm looking for a Computer Algebra System to run in a browser, with a particular interest in finding roots to systems of equations.

I'm currently evaluating Coffeequate.

The simplest non-trivial system I came up with that wasn't on the demo page was a system of two simultaneous linear equations:

var exp1 = CQ('x = 2 * y + 6');
var exp2 = CQ('x - y = 10');

exp2.sub({x: exp1.solve('x')})
    .solve('y');

Unfortunately, this hangs at the sub call.

What I would like to obtain is the value for all unknowns (i.e. x and y) that are knowable – there is guaranteed to be a solution in this case.

What am I doing wrong here?

jamesh
  • 19,863
  • 14
  • 56
  • 96

1 Answers1

3

CQ().solve returns an array of solutions (in case there are multiple solutions). However, things that you want to substitute in using CQ().sub have to be integers or CQ() objects themselves. The following code works:

var exp1 = CQ('x = 2 * y + 6');
var exp2 = CQ('x - y = 10');

exp2.sub({x: exp1.solve('x')[0]}).solve('y'); // 4

The fact that it actually hangs instead of erroring when you pass in an array is a bug; I'll patch that.

(Disclaimer: I wrote Coffeequate)

Matthew
  • 2,232
  • 4
  • 23
  • 37