Jay Smith wrote: Please look at the attached worksheet (M15) ... I'm new at programming and I'm having difficulty getting the hang of it. |
See attached for a possible solution. Among other things you used the wrong (literal, instead of vector) index and demanded the value 0 at a log scale.
Can constants (scalars, vectors) that are defined outside the program block be referenced inside the program block and vice versa? |
You can reference sheet variables in a program, but you cannot change them. In other words, if a variable is on the LHS of an assignment it is considered a local variable of the propgram and is not related to a a sheet variable of the same name. If a variable is referenced on the RHS of an assignment Mathcad will look if there is a local variable with that name and if not it will take the value of the sheet variable with the name. So for a program to change a worksheet variable the only possibility is to assign that variable the result of the program.
Also, what exactly is the purpose of the 'return' command? ... seems like it can be left off sometimes. What in this case would I return? |
You can omit the return in every case and just write the expression you want to return. using return is good programming style, though. Furthermore the return statement will terminate execution of the program. If no return is used the program return the last expression value. See at the end of the attached file a simple example.