# [?] Convert units with UnitConvert and CurrencyConvert?

Posted 2 years ago
3033 Views
|
6 Replies
|
4 Total Likes
|
 I am a novice user, trying to work through some examples given in book about Mathematica, and I am confused about the output I am receiving. Here is what I am entering, and the output is the same as my input - any idea what I am doing wrong? I have attached the notebook - called "Input equals output" In:= UnitConvert[26.2 mi, km] Out= UnitConvert[26.2 mi, km] In:= CurrencyConvert[\$10 .00, Quantity[1, "Euros"]] During evaluation of In:= Quantity::compat: DimensionlessUnit and Euros are incompatible units Out= CurrencyConvert[0., Quantity[1, "Euros"]] Attachments: Answer
6 Replies
Sort By:
Posted 2 years ago
 Hi Mac,UnitConvert takes a Quantity as its first argument. Most units need to be specified as strings. UnitConvert[Quantity[26.2, "Miles"], "Kilometers"] CurrencyConvert[Quantity[10, "USDollars"], "Euros"] Explore the documentation. Answer
Posted 2 years ago
 Thank you - that makes sense - this book example is incorrect, and your solution works. Many thanks, Mac Answer
Posted 2 years ago
 Hi Mac,To expand a little on Eleazar's answer. As a newcomer to WL it is important to understand that unlike most programming languages, WL uses term rewriting. When you define a function, you are actually defining a rewriting or replacement rule.This defines a replacement where f[] is replaced by ^2. Clear[f, a, b] f[x_] := x^2 f (* 4 *) f[a + b] (* (a + b)^2 *) A replacement rule may also restrict the patterns to which it applies. This definition will only apply if the argument to f is an Integer. a + b is not an Integer so no replacement is performed (output = input). Clear[f, a, b] f[x_Integer] := x^2 f (* 4 *) f[a + b] (* f[a + b] *) If you are interested in exploring this aspect of the language further, read this post and the many links it references. Answer
Posted 2 years ago
 Note that Mathematica uses some pretty formatting on expressions as well. For example, Quantity expressions format in a human-readable way: Notice the slightly lighter text colour.So the book is likely correct as well.Other examples of formatted content include: Entity expressions (in an orange box), DateObject expressions (grey box with an icon). Answer
Posted 2 years ago
 I dont know if this is what youre asking, but if the input code has been written incorrectly, the output (the result) will be the same as the input code. And usually Mathematica will tell you what you did wrong. Example: PersonData[BrianJacques, NotableBooks the output would be: PersonData[BrianJacques, NotableBooks and then Mathematica would tell you that you didnt type an ending right square bracket. Answer
Posted 2 years ago
 Thanks - there was no error code, but the solution was provided above. I appreciate your help! Answer