Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
483 views
%md This is quick worksheet that hits the basics of defining your own user-built function. Except for a few names, you can give a function just about any name you want. Also, the function can have as many *arguments* as you want and the arguments can stand for numbers, expressions or other functions. I will start with function that when given $m$ and $b$, will create the right side of a slope-intercept linear equation. After that, I will create a similar function whose output will be a point-slope intercept form of a straight line using the values $m$, $x0$, $y0$. The basic code for making your own **user-defined** functions is: def *fn name(var1,var2,var3,...)*: return you want it to output

This is quick worksheet that hits the basics of defining your own user-built function. Except for a few names, you can give a function just about any name you want. Also, the function can have as many arguments as you want and the arguments can stand for numbers, expressions or other functions. I will start with function that when given mm and bb, will create the right side of a slope-intercept linear equation. After that, I will create a similar function whose output will be a point-slope intercept form of a straight line using the values mm, x0x0, y0y0.

The basic code for making your own user-defined functions is:

def fn name(var1,var2,var3,...):

return you want it to output
m,x0,y0,b=var('m,x0,y0,b') #always safe to declare variables!!! def slope_int_eqn(m,b): return m*x+b#notice the indent! #I will test it with m=2 and b=3 slope_int_eqn(2,3) #here's the second example def point_slope_eqn(m,x0,y0): return m*(x-x0)+y0 #I will test it with m=2, x0=3, y0=4. when you execute you will notice that cocalc simplifies the result. point_slope_eqn(2,3,4)
2*x + 3 2*x - 2