Navigation
Main Page
Random Page
Create a new Page
All Pages
Categories
Administration
File Management
Login/Logout
Language Selection
Your Profile
Create Account
Quick Search
Advanced Search »
Back
History
User functions
'''User Functions''' are functions that you write yourself. They can only return a single value or a matrix. ==[anchor|#Examples]Examples== Here's a function to round a floating point number down to the next integer smaller than or equal to the argument. [imageauto|floor function|{UP}floor/smath_floor.jpg|floor/smath_floor.jpg] ---- Here's a function that returns a matrix. I didn't say it was a useful function. [imageauto|funny matrix function|{UP}floor/smath_user_func2.jpg|floor/smath_user_func2.jpg] As one could see function is defined by its name and arguments given in parenthesis like: '''f(x,y):=x+y+a+2.5-f(x)+f(y)-f''' On the LHS of the assignment operator there is '''f''' as the function name, '''x,y''' are function fictive (dummy) arguments. On the RHS is the function definition by an expression. As one can note, functions can have the same name, and are distinguished by different number of arguments like '''f(x,y)'''-two arguments, '''f(x)'''-one argument. Even '''f''' as a variable can exist. Function is called by its name and real arguments. Real arguments can be constants, variables and expression. Function is returning a value and, therefore, may be as a part of an expression. Besides variables, function can have another function as an argument. Here is an example: [imageauto|function as function argument|{UP}userfunchints/funasfunarg.png|userfunchints/funasfunarg.png] ==[anchor|#Hints]Hints== ===[anchor|#Redefining_inputs]Redefining the Inputs to a Function=== Shown below is a common mistake: [imageauto|common mistake|{UP}userfunchints/common mistake.png] Explanation: The common mistake shown above is avoided if the function is defined first. The variables should be assigned to their desired values only after the function is defined. Smath (like Mathcad) calculates from the top-left corner towards the bottom-right corner of the worksheet; therefore, if a variable is defined and then a function is defined using that variable, Smath defines the new function using the previously assigned VALUE of the variable. Changing the variable lower on the worksheet cannot redefine the function because the function was defined higher up on the worksheet. Therefore, if the user wants to be able to edit variable values used within a function, the function must be defined first using previously UNDEFINED variables and then the variables can be defined (and redefined as many times as desired) lower down on the worksheet. See graphic below for correct usage: [imageauto|correct usage|{UP}userfunchints/correct_user_function_definition.png] ===[anchor|#Function_Overloading]Function Overloading=== [imageauto|Functions can have the same name |{UP}userfunchints/the same name.png] ===[anchor|#Reserved_Words]Reserved Words=== [imageauto|Reserved words?|{UP}userfunchints/reserved words.png] [imageauto|Redefining SMath function - take care!|{UP}userfunchints/redefining SMath function.png] ===[anchor|#Arguments_as_Scalars_or_Matrices]Arguments as Scalars or Matrices=== [imageauto|Scalar? Matrix? arguments|{UP}userfunchints/scalar matrix argument.png] ===[anchor|#Defining_Functions_with_for_Loop]Defining Functions with 'for' Loop=== [imageauto|Using for loop|{UP}userfunchints/using for.png] ==[anchor|#Editing]Editing== Multi-rename: To start changing names of the variables, functions, units, numbers or empty placeholders with the same names user will need just put the cursor on the primitive in interest and press F8 keyboard button. As a result several cursors will be drawn on the canvas and user will be able to manage all these cursors at the same time! To deactivate this feature one should press F8 button again or press ESC + several ways implemented to deactivate it automatically (on click, if cursor will jump to another element and etc.). Here is how it looks like: {{{{[image||http://smath.info/?file=739326&type=image]}}}}
ScrewTurn Wiki
version 2.0.37. Some of the icons created by
FamFamFam
.