Message Boards Message Boards

0
|
3848 Views
|
12 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Strange results from Reduce and D in Mathematica

Posted 11 years ago

Why does: Reduce[4 x^3 - 9 x^2 + 4 = 0, x] Yield: Set::write: Tag Plus in 4-9 x^2+4 x^3 is Protected. >> Reduce::naqs: 0 is not a quantified system of equations and inequalities. >> ??

Why does: D[4 x - 3 x^3 + x^4, x] Give an answer of 0?

?x gives Global`x So it's not that x is evaluating to some number. This is also proved by typing 4 x^3 - 9 x^2 + 4 and getting 4 - 9 x^2 + 4 x^3 back.

By the way: D[x^4,x] results in 4x^3

And

D[x^4-3x^3,x] results in -9x^2+4x^3

Only when I append the "+4x" to the expression does the program seem to lose its mind!

POSTED BY: Kim Helliwell
12 Replies

Dear Kim,

this is what I get when I evaluate your notebook:

enter image description here

All the outputs are as expected. D[f,x] evaluates to zero because you haven't given the independent variable a name. So that is as expected. D[f[X],x] evaluates to zero because I calculate the derivative with respect to a variable that is not in the function as X and x are different.

The notebook that you sent

enter image description here

is quite the same as mine apart from the offending output where D[f[x],x] which evaluates to zero. If I re-evaluate your notebook the zero changes into the correct output.

Have you restarted your kernel? Have you tried using

ClearAll["Global`*"]

I cannot reproduce the error you get.

Best wishes, Marco

POSTED BY: Marco Thiel
Posted 11 years ago

Marco:

Thanks for your work on this problem. Restarting the kernel did the trick. I suspect that, at one point, I said something like:

D[f[x],x]=0

That is, I made an assignment to the derivative, rather than a comparison, and that might be the root of the problem. I did try the ClearAll function, but that did not clear whatever was the issue with the bad command. Restarting the kernel seems to have cured it.

So I think it's mostly explained, at least to the point that I can move on to other things now.

Thanks again,

Kim

POSTED BY: Kim Helliwell
Posted 11 years ago

See if you can work through the attached notebook a line at a time and understand why each line works or doesn't work as expected.

Attachments:
POSTED BY: Bill Simpson
Posted 11 years ago

Also, Marco: I tried your notebook with the same result. And you can note, from my notebook that I get correct answers if the final term (4x) is either not there or is 4, rather than 4x.

POSTED BY: Kim Helliwell
Posted 11 years ago

OK, here is a short notebook that shows the problem.

Attachments:
POSTED BY: Kim Helliwell

There must be something wrong in the post - perhaps the type setting. You are writing

 f[x_]=4x-3x^3+x*4

This is different from what you said before, because the polynomial was:

4x-3x^3+x^4

Also to define a function you should use:

 f[x_] :=4x-3x^3+x^4

so the delayed assignment ":=" instead of "=". Then you say

"D[f[x],x] gives 0, but D[f[x],x] gives the expected answer". That is the same (!!!) expression. How can it give two different answers?

I think that it would be easier if you attached the notebook. Small typos can make it difficult to find the error. I'll attach a notebook that does work.

M.

Attachments:
POSTED BY: Marco Thiel
Posted 11 years ago

If f is defined as: f[x_]=4x-3x^3+x*4, then: D[f[x],x] gives 0, but D[f[x],x] gives the expected answer. Is there a clue in that?

POSTED BY: Kim Helliwell

Well, I guess we cannot reproduce your D[x^4-3x^3+4x,x] problem. Would you mind attaching the notebook?

M.

POSTED BY: Marco Thiel
Posted 11 years ago

Well, not so fast. Still don't know why the D misbehaves, but the Reduce thing works with ==.

POSTED BY: Kim Helliwell
Posted 11 years ago

Aha! So I set D[x^4-3x^3+4x,x] to 0 Since that equals 4x^3-9x+4, I guess that Reduce is trying to reduce 0!

All is clear now, thanks!

POSTED BY: Kim Helliwell

Yes, the second one, I cannot replicate either.

D[4 x - 3 x^3 + x^4, x]

Gives the correct result. Also if x was predefined you would get an error message. For example

x = 2; D[4 x - 3 x^3 + x^4, x]

General::ivar: 2 is not a valid variable. >>

So that cannot be it. The only way that I get 0 is if I derive with respect so some other variable such as

D[4 x - 3 x^3 + x^4, X]

where the last X is capitalised.

M.

POSTED BY: Marco Thiel

For the first, check documentation for the differente between Set (infix =) and Equal (infix ==). I cannot replicate the second.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract