How to use recursion in Maple...

I was trying to write a procedure that would compute a simple linear equation using the Extended Euclidean Algorithm. I was thinking of a procedure like the following:

``````solveEeaMatrix := proc (a::list, b::list)
local c::list;
c := a -iquo(a[1],b[1])*b;
print(c);
while (c[1] <> gcd(a[1],b[1]) do
...
``````

I am basically stuck at this part as

1) I don't know how to setup a multi-dimensional array that could dynamically grow(as a possible solution).

2) I can't come up with a recursive function that could possibly take care of this.

In short, if I am given for example an equation like: `84*x+203*y = 14`

I will transform it into 2 linear equation as follow:
`row0 := [203, 0, 1] row1 := [84, 1, 0] `Subsequently, I will perform the following:

``````c := a -iquo(a[1],b[1])*b;
``````

Where `a`and `b` are both lists and arguments of the procedure and `c`being another list and a local variable.

But I don't know how to do the following programmatically:

``````row3 := row1-iquo(row1[1], row2[1])*row2;
row4 := row2-iquo(row2[1], row3[1])*row3;
row5 := row3-iquo(row3[1], row4[1])*row4;
and so on ...
``````

Any hint would be appreciated.

Simple procedures and plots...

Hello everyone,

I'm currently taking a Chaos and Fractal Geometry class that did not have a pre-req of computer programming or knowledge of Maple, but I am apparently the only person in the class who has not taken a class/does not have this knowledge so my professor really flew by teaching the material. My sob story aside, I was hoping you great people would be able to help me out with (what are apparently) really basic procedures and plots while I try to read up on how to actaully do it myself (if anyone has a good supplement to recommend, I'm all ears!). Anyway, here are the one's that I'm stumped on:

• "Write a Maple proc L that takes as input two lists and returns as output a set containing the terms they have in common (not necessarily in the same position). For example, L([1, 3, x, 5],[2, x, 5, 2, 1, 8]) should return [1, x, 5]."
I'm thinking this is going to use some form of the intersection command, but I cannot for the life of me figure out how to set up the syntax
• "Write a Maple program that implements the Euclidean algorithm to compute the gcd(x, y) for any natural numbers x, y (except x = y = 0). Your program should not just compute the gcd, but should do so by implementing the Euclidean algorithm directly (i.e. proc(x,y) RETURN(gcd(x,y)) end; is not what I am looking for here! :) )."
If only he would've let me do the easy one :(
• "Write a Maple program to plot the Pythagorean spiral. The program should take a single positive integer n as an argument and plot the spiral until the side of length n is reached"
Not even a clue on how to approach this one.

Thanks again to any and all help/recommendations you can make. I really appreciate it!

Extended Euclidean Algorithm ...

This is my code for the Extended Euclidean Algorthim which should return integer l, polynomials pi,ri,si,ti for 0<=i<=l+1. And polynomial qi for 1<=i<=l such that si(f)+ti(g) = ri and sl(f)+tl(g)=rl=GCD(f,g).
The problem is, I keep getting division by zero. Also it evaluates pi = lcoeff(ri-1 - qiri) to be zero, everytime. Even when I remove this it still says there is a division of zero, which must be coming from qi:=quo(ri-1,ri, x); however I do not know why considering the requirements for the loop are that r[i] not equal zero. I really could use a fresh pair of eyes to see what I've done wrong. Any help would be greatly appreciated!!

Two sets of points in the plane

by: Maple

Consider two sets in the Euclidean plane, each consisting of 4 points.

First set:  A(0, 0),  B(3, 4),  C(12, 4),  E(4, -1)

Second set:  F(0, -8),  G(12, -4),  H(9, -8),  K(4, -9)

It is easy to check that the set of all pairwise distances between the points of each of the given sets (6 numbers for each set ) are the same. At the same time it is obvious that there is no any...