Document 451 User-defined MuPAD functions in Scientific NotebookVersion: 4.x & 5.x - Scientific WorkPlace & Scientific Notebook First, though, here are a few examples of the usage and output of the user-defined procedures discussed here:
Of course, those are just very few examples of what can be done by calling user-defined MuPAD procedures from within a Scientific Notebook document. At the end of this article, there is a link that you can use to download the source file that contains those three MuPAD procedures. If you are a Scientific Notebook (or Scientific WorkPlace) user, you might want to read through the article once and then download the source file and follow the instructions to implement the functions in one of your own documents. Now, let's use the last example in the list above (determine the base-7 integer representation of the base-10 integer ) and go through the steps necessary to accomplish that in a Scientific Notebook document. Notes:
Before we start, make sure you're using the MuPAD engine:
The specific tasks in this type of process are to
Develop a specific MuPAD procedure or obtain one from someone elseWhile we won't go into very many details here about creating your own MuPAD procedure, a few comments might be helpful. The MuPAD procedure must be in a MuPAD source file, which is just a text file with a .mu extension. Because that file is a text file, you can create such a procedure outside of the MuPAD Pro 2.0 environment. In that case, however, you would not easily be able to test and debug the procedure during development. For the purposes of this article, we will describe the use of a procedure called changeFromBase10 that is stored in a source file called userFcns.mu. As you'll see below, that procedure accepts two input arguments, a base-10 integer and a new base designation (between 2 and 10). It then returns the equivalent integer representation in the new base. Notes:
Create a new Math name for use in calling that procedureIn many similar instances, as here, we would like to create the new function name in Scientific Notebook to be the same as the one used to develop the procedure in MuPAD Pro 2.0. For that purpose in Scientific Notebook, you will need to use what is referred to as a Math Name. The steps here are as follows:
The new Math Name
is inserted into your document wherever the cursor is. In addition, whenever you are in math mode and type the Math Name that was just created, it will be automatically recognized by Scientific Notebook. That is, it will change from to when you type the last character of the function name. A brief word of caution here: when creating a new Math Name, don't try to use a sequence of characters that contains an already defined Math Name. For example, you couldn't properly create and use a Math Name called mysinfunc because it contains the already defined special Math Name . Before you could finish typing that name in math mode, the sin would be automatically recognized and the result would look like . Map the MuPAD procedure to the new Math NameRecall from above that this step, as described here, assumes that there is a procedure called changeFromBase10 that is stored in a file called userFcns.mu in a MuPAD\UserFcns subfolder of the local Scientific Notebook installation. Don't be too worried if that comment sounds confusing at this point. It should become a little bit clearer as you read through the specific steps below. The steps here are as follows:
Use the newly mapped procedure in a Scientific Notebook documentIn order to use the newly mapped procedure, you merely need to type the argument call in math mode and then select Compute/Evaluate. An example call is shown below:
Students could, for example, be asked to demonstrate their understanding of the base-n representation of a number by using the above procedure, independently producing the base-n expansion, and using Scientific Notebook to compare the two. For instance:
(using Compute/Evaluate) or (using Compute/Evaluate) or
is true
(using Compute/Check Equality) Tip: Create a "shell" from a documentAfter you have made one or more definitions (mappings) as described above, you can create a shell document that will preserve those definitions for use in the development of other documents. For more information on shell documents, select Search... from the Help menu, type shells into field 1, select Shell documents in field 3, then click the OK button. Some comments about the MuPAD proceduresThere are three procedures defined in the userFcns.mu file referred to throughout this article:
Click here to download a copy of the userFcns.mu file. If you have an idea for a procedure and you'd like some assistance in implementing it, or if you have a working MuPAD procedure that you'd like to offer for use by others, please email us. If you have SWP, SW, or SNB, you can open the .rap version of this document that is available on our website. Last revised 03/13/06 This document was created with Scientific WorkPlace. |