Calculating Derivative of f[x] - Why Does Mathematica Give Incorrect Output?

In summary, there was a conversation about a mathematical function and its derivative. The user was having trouble getting the correct output from Mathematica, but it turned out that the issue was with the formatting of the function. With proper use of parentheses and operators, the correct derivative was obtained. The conversation also highlighted the importance of properly formatting mathematical expressions in Mathematica.
  • #1
ktpr2
192
0
I have

f[x_] := ax+b/2x+d
f'[x]

and I get

-2(ax+b)/(d+2x)^2

instead of

ad-2b/(d+2x)^2

Assuming the above, my answer, is correct, why does mathemetica give me its answer? Is it interpreting one of the variables as some kind of weird constant?
 
Physics news on Phys.org
  • #2
no one has any idea what might be wrong?
 
  • #3
You're not using parentheses properly. The / operator has a higher precedence than the + operator. Try:

f[x_] := (ax+b)/(2x+d)

- Warren
 
  • #4
Oops, nevermind. The problem is that Mathematica thinks "ax," without spaces, is a variable unto itself, different from either a or x. You need to use either spaces or the * operator to indicate multiplication:

f[x_] := (a*x+b)/(2x+d)

- Warren
 
  • #5
Which answer is yours and which answer is mathematica's.

The answer I get is the ad-2b/(d+2x)^2, the -2(ax+b)/(d+2x)^2 comes from doing only half of the quotient rule equation.

EDIT: Or just follow the advice above :tongue:
 
Last edited:
  • #6
that makes sense. thanks a lot. I'm seeing how delicate things have to be formated. For instance, I just ran into another thing where I realized that my trig functions have to have bracketed variable inputs (Cos [x]) as opposed to Cos (x) which is something else.
 

1. Why is the derivative of my function not giving the correct result in Mathematica?

There are a few possible reasons for this. First, make sure that you have properly defined your function and its variables. Also, check if you have used the correct syntax for taking the derivative in Mathematica. Additionally, the derivative function in Mathematica uses numerical methods and may not always give exact results. You can try increasing the precision of your calculations to get a more accurate result.

2. Can I manually specify the points at which the derivative is calculated?

Yes, you can use the "Derivative" function in Mathematica to specify the points at which you want to calculate the derivative of your function. This can be helpful if you want to avoid any numerical errors or if you want to calculate the derivative at specific points for analysis purposes.

3. Why does the derivative function sometimes return a complicated expression instead of a simplified result?

This can happen if your function is defined using piecewise or conditional statements. In such cases, Mathematica may not be able to simplify the derivative expression and will return it in its most general form. You can try using the "Simplify" function to simplify the derivative expression.

4. How can I plot the derivative of my function in Mathematica?

You can use the "Plot" function in Mathematica to plot the derivative of your function. Simply use the derivative function within the "Plot" command and specify the range of values for the independent variable. This will give you a visual representation of the slope of your function at different points.

5. Is it possible to calculate higher-order derivatives in Mathematica?

Yes, you can use the "D" function in Mathematica to calculate higher-order derivatives. Simply specify the order of the derivative as the second argument in the "D" function. For example, "D[f[x],{x,2}]" will calculate the second derivative of f[x] with respect to x.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
2
Views
529
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
8K
  • Calculus and Beyond Homework Help
Replies
23
Views
1K
Replies
1
Views
175
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top