Join Curt Frye for an in-depth discussion in this video Calculating values using built-in functions and variables in Mathematica, part of Learning Mathematica 9.

Mathematica is a powerful analytical environment. Part of its power is that it has a huge number of built-in expressions and functions that you can use to evaluate your data. In this movie, I will show you some of the most frequently used ones, and also show you how to use them inside of the program. To start, I'll just give you a quick overview of some of the functions that I'll demonstrate a little bit later once I get into a mathematica notebook. The first function is square root. That's S-Q-R-T and that just finds the square root of a number.

Next is integerPart, that returns the integer component of a real number. That is a number that can have a decimal component afterwards. Ceiling rounds the number up regardless of the decimal component, so for example, 14.1 would be rounded up to 15. Floor rounds a number down, and that rounds the number down to its closest integer, so for example, 14.9 would be rounded down to 14. Round rounds a number to the closest integer with the rule that anything below 0.5 goes down, anything 0.5 or higher goes up.

Max finds the largest number in an input set. Min finds the smallest number. Factorial finds the factorial of an input. And you can indicate that using the factorial function or a number followed by an exclamation mark. Factorial is when you multiply a number by all the numbers below it in succession. So for example, five factorial would be five times four times three times two times one, which equals 120. Then finally, you can use the value for Pi by simply using the keyword Pi and that's 3.14159 and so on.

One interesting and sometimes fun thing you can do inside of mathematica, is to list out the digits of Pi to a particular arbitrary length. So for example, if someone tells you that he or she can recite the first 100 digits of Pi and you have mathematica open, you can type in N, and then in square brackets Pi, the number 100, press Shift+Enter and see how they do. With that introduction in place, let's switch over to mathematica, and see how they work in practice. All right, I am back in Mathematica, and let's say that I want to find the square root of a number, say the square root of the number 75.

For that, I would type in S-Q-R-T, and then square bracket, the number 75, close the square bracket, and Shift+Enter to evaluate and they get five times the square root of three. If I want to display that result as a number as opposed to a symbolic expression. Then I can type N, left square bracket and then square root, left square bracket is 75 and then two right square brackets to close out the expression, Shift+Enter and I get my result of 8.66025.

There are two things that I'll point out before I go on to demonstrating further built in functions. The first is that function names always begin with a capital letter. That's to distinguish them from variables inside the mathematica framework. Second, note that in most cases, the arguments that you type for these built-in functions go in between square brackets. So if you're like me, and you're used to working in Microsoft Excel, where everything in formulas goes inside of parentheses, you'll have to learn a new habit when you're working in mathematica.

It takes a little bit of time, but I think you'll agree that it's worth it. Okay, let's go on with some more examples. Suppose that I multiple to apply the value of Pi times 18, and Shift+Enter to get the result. I have 18 times pi, and of course, if I want the numerical value of the most recent calculation as I've shown you in another movie. I can just type N then left square bracket, a percent sign, right square bracket, Shift+Enter and I get the value of 56.5487. Now let's say that I have a list of values, and lists are something I will deal with later in the course, let's say that I have alist equals and then a left curly bracket 14, 15, eight, three, 18, 9 and then a right curly bracket.

So I have a variable named alist and then inside of curly brackets, I have the numbers 14, 15, eight, three, 18 and 9 and I'll press Shift+Enter so there is my output, and I have my list. Now let's say that I want to find the minimum value and the variable alist. So for that, I'll just type M-I-N, left square bracket alist. Here you can see that it's coming up in auto complete because I defined it as a variable and it's now at least temporarily a keyword.

Then a right square bracket and Shift+Enter. And I get the minimum value of three which is correct. Now let's do the same thing for max, M-A-X, alist, and alist is within square brackets, Shift+Enter. I get the number 18 which is the largest number in that collection. Now let's say that I want to round numbers up or down. So let's say that I round R-O-U-N-D, left square bracket 14.85, then a right square bracket and Shift+Enter, get the number 15 because we are rounding up.

If I did round left square bracket 14.3 and then a right square bracket and Shift+Enter, it would go down to 14, and I'll just scroll down with my scroll wheel so I'm a little bit closer to the middle of the screen. I could also use Floor, F-L-O-O-R, left square bracket 14.85. Now remember this function rounds down if there's any decimal component, so when I press Shift+Enter, we get 14. And finally, if I want to display the first 100 digits of Pi, I can do so using the N, which is the numerical expression.

So I have N, left square bracket, Pi, 100, right square bracket, and Shift+Enter and I get, Pi to the first 100 digits. As I said at the beginning of this movie, there are literally thousands of built in functions, that you can use in Mathematica. What I've shown you in this movie gives you the tools that you can use to learn more about the functions, and to use the most common ones effectively inside of your notebooks.

###### Released

4/21/2014Curt Frye teaches you how to set up Mathematica notebooks, assign values to variables, perform simple calculations, create and manipulate matrices, enter equations in linear and descriptive form, write and debug Mathematica scripts, and visualize data with charts.

NOTE: Basic knowledge of linear algebra is helpful for this course, but not required.

- Managing Mathematica workbooks
- Assigning values to variables
- Calculating values with built-in functions
- Manipulating matrices
- Importing and exporting data
- Defining functions
- Creating charts

## Share this video

## Embed this video

Video: Calculating values using built-in functions and variables in Mathematica