Question

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.

Était-ce utile?

La solution

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.

Autres conseils

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

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.

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top