3

I have to do some computations where long formulae, mainly involving derivatives of polynomials with variable coefficients come up.

Unfortunately the results I obtain from engines like Mathematica or Maple are represented in a way that is very different to those I need, and rearranging the result into the desirable form takes too long (not to mention the risk of re-introducing errors).

Hence I was wondering whether there is some way to instead do the computations myself and then let the result be checked – i.e. some sort of "equation checker":

I put in d/dx f(x) = g(x) where I provide BOTH sides and the system evaluates this to be true or false.

horchler
  • 18,384
  • 4
  • 37
  • 73
harlekin
  • 315
  • 2
  • 7

4 Answers4

4

I would check out sym/isequaln. It is an overloaded version of isequaln used to compare symbolic expressions. For example:

syms x
f(x) = 3*x^3-2*ln(x);
g(x) = 9*x^2 - 2/x;
isequaln(f,g)

ans =
    0

isequaln(diff(f), g)

ans = 
    1

See the MathWorks documentation on the function. It's pretty handy.

horchler
  • 18,384
  • 4
  • 37
  • 73
zachd1_618
  • 4,210
  • 6
  • 34
  • 47
  • FYI, I believe that the symbolic version is [R2013a+](http://www.mathworks.com/help/symbolic/release-notes.html#btp1z74-1). The numeric version is R2012a+, but it just replaced the horribly named `isequalwithequalnans`. – horchler Nov 13 '13 at 02:56
2

In Maple, use is(f=g). If the result is FAIL, then set _EnvTry:= hard; and try the is command again.

Carl Love
  • 1,461
  • 8
  • 7
1

In slightly older versions of Matlab (back to R2012a), one can use the isAlways as a way to test symbolic equations. This function is also useful for testing inequalities. Just don't forget that the "A" is capitalized in the function name. Taking the liberty to use @zachd1_618's example:

syms x;
f = 3*x^3-2*log(x);
g = 9*x^2 - 2/x;
isAlways(f == g)

returns 0, but

isAlways(diff(f,x) == g)

returns 1.

In using either isequaln or isAlways, it's a good idea to take advantage of assumptions. Also interesting is sym/logical:

syms x;
isAlways(1 == sin(x)^2+cos(x)^2)

returns 1, but

logical(1 == sin(x)^2+cos(x)^2)

returns 0 because it does not simplify the expressions before comparing.

horchler
  • 18,384
  • 4
  • 37
  • 73
1
f = 3 x^3 - 2 Log[x];
g = 9 x^2 - 2/x;
PossibleZeroQ[f - g]
PossibleZeroQ[D[f, x] - g]
D[f, x] == g

False

True

True

chyanog
  • 599
  • 5
  • 14
  • typically you will need to use Simplify on the direct equality test – agentp Nov 13 '13 at 12:41
  • I'd second george to only use `PossibleZeroQ` as a fast first check. `Simplify` and `FullSimplify` are what you really should use. You'll find that these often fail to confirm seemingly correct relations because of implicit assumptions you are making, similar to what horcher wrote in his answer using the matlab symbolic toolbox. You can use the `Assumptions` option to let Mathematica know about such restrictions. – Albert Retey Nov 13 '13 at 13:55