## Doing Math by SWP How we can implement recursive formulae in SWP's computer algebra facility? Hi

fibonacci := proc(n)
local x;
begin
if n=1 then x := 0
elif n=2 then x := 1
else
x := fibonacci(n-2)+fibonacci(n-1):
end_if:
return(x);
end_proc:

as the procedure.

### Thanks to John M. for the

Thanks to John M. for the revision. This works well. ### I have been able to use

I have been able to use piecewise function notation to do recursive functions. (See help files if you don't know how to do this.) Let f(x) =

1 if x = 1

1 if x = 2

f(x-1)+f(x-2) if x > 2

Define function, and evaluate at any positive integer.

Note: The subscript notation for a function argument won't work here. ### Re: Doing Math by SWP

The Scientific WorkPlace interface does not directly support recursive functions, but you can write recursive functions in MuPAD code and access the function using the Define MuPAD Name function.

An example of a simple function which finds the nth number in the fibonacci series can be written as follows in an ASCII editor (such as Notepad):

fibonacci := proc(n)
local x;
begin
if n=1 then x := 0
else
if n=2 then x := 1:
end_if:
else
x := fibonacci(n-2)+fibonnacci(n-1):
end_if:
return(x);
end proc:

You can then save this function in a file named, say, fib.mu and access it as follows:

1. Choose Compute, Definitions, Define MuPAD name.

2. Enter

fibonacci(n)

3. Enter

f(n)

as the Scientific WorkPlace name. You can name this function anything you want. It is only important that the argument list of the MuPAD name and the Scientific WorkPlace name match.

4. Under "The MuPAD Name is a procedure", select "In MuPAD format file (.mu file)".

5. Enter the path and name of the fib.mu file created with the ASCII editor.

6. Click OK.

At this point, you should be able to evaluate f(5) and get 3. 