Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

My question is very basic, When using the Differentiate functionality of Mathematica in this way:

D[0.5 x^2, x]

This results in:

1.x

I don't need the 1. but how can I tell mathematica to remove this? It works further along in my code and gives me results like:

{{1. m, 0, 0}, {0, 1. m, 0}, {0, 0, 1. Jcm}}

Any ideas?

share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

Do you have the possibility to enter fractional values beforehand?

D[(1/2) x^2, x]

which gives

x
share|improve this answer
add comment

You could use Rationalize:

Rationalize[D[0.5 x^2, x]]

x

Rationalize[{{1. m, 0, 0}, {0, 1. m, 0}, {0, 0, 1. Jcm}}]

{{m, 0, 0}, {0, m, 0}, {0, 0, Jcm}}

share|improve this answer
add comment
expr1 = D[0.5 x^2, x]
expr2 = D[0.25 x^4, x]

(* 1. x  *)

(* 1. x^3  *)

Then

    expr1[[2]]
    expr2[[2]]

  (*  x *)

  (*  x^3  *)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.