0
|
2650 Views
|
12 Replies
|
4 Total Likes
View groups...
Share
GROUPS:

# Strange results from Reduce and D in Mathematica

Posted 10 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 Globalx 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!
12 Replies
Sort By:
Posted 10 years ago
 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 10 years ago
 OK, here is a short notebook that shows the problem. Attachments:
Posted 10 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 10 years ago
 Dear Kim,this is what I get when I evaluate your notebook: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 sentis 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 10 years ago
 For the first, check documentation for the differente between Set (infix =) and Equal (infix ==). I cannot replicate the second.
Posted 10 years ago
 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 10 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 10 years ago
 Well, not so fast. Still don't know why the D misbehaves, but the Reduce thing works with ==.
Posted 10 years ago
 Well, I guess we cannot reproduce your D[x^4-3x^3+4x,x] problem. Would you mind attaching the notebook?M.
Posted 10 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 10 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 10 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]=0That 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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.