(practical-function)= # Exercise 10: A more practical function Your task is to repeat {ref}`more-physics` by writing a function to compute $E_{loss}$: :::{math} E_{meas}^{2} = p_{x}^{2} + p_{y}^{2} + p_{z}^{2} E_{loss} = E_{beam} - E_{meas} ::: You'll create a new **`eloss`** column in the n-tuple, but that's the *only* new column you're going to create. You are to write a function that will take the needed columns from the n-tuple and return a value for $E_{loss}$, use that function in a `Define`, then make a scatterplot of this new column against **`zv`**.[^smart-aleck] [^smart-aleck]: You can try to be clever and do this: eloss_df = dataframe.Define("eloss","ebeam-sqrt(px*px+py*py+pz*pz)") But you know that's not what I'm asking for. For a real physics project, you're going to be asked to performed calculations that can't be shoved into a simple one-line text string. Write an actual function so you can learn how it's done. No, you don't have to use a lambda expression. Unless, of course, you want to show how cool you are. :::{hint} Look at the available columns in the n-tuple. Compare that with above formulas. Which of those columns will you need to compute those equations? How many arguments will your function take? ::: :::{figure-md} equations-fig :align: center xkcd equations by Randall Munroe :::