Running multiline Maple program

309 Views Asked by At

I am working on the question below, which I have copied from a PDF file. I have determined what the program does (Euclidian algorithm), but I need helping running the actual program. I am instructed to use the "text insertion" feature. I am using Maple 16 for Mac. I go to Insert:Text and then paste the given code (I've included this below) in the Workspace. If I select the code and then use Edit:Execute:Selection I get errors saying "unable to match delimiter". Any help with how to execute this program and use my own inputs would be greatly appreciated. Do the number of spaces for blocking the code matter, etc?

Picture of question from PDF

Code (without any line indents):

euclid:= proc(m,n) local q,r1,r2,r3;
r1:=m; r2:=n;
while r2 <> 0 do;
q:=iquo(r1,r2); r3:= irem(r1,r2);
lprint(r1, ‘=‘, q, ‘*‘, r2, ‘+‘, r3);
r1:=r2; r2:=r3; od;
RETURN(r1); end;
1

There are 1 best solutions below

4
On BEST ANSWER

Something went awry when you copied from the pdf. The quotation marks are incorrect. Try replacing them with " or `. Typographic quotation marks won't work.


Added: Try copy-pasting this:

euclid := proc (m, n) 
local q, r1, r2, r3; 
r1 := m; r2 := n; 
while r2 <> 0 do;
q := iquo(r1, r2); r3 := irem(r1, r2); 
lprint(r1, "=", q, "*", r2, "+", r3); 
r1 := r2; r2 := r3; 
od; 
RETURN(r1) 
end;

This works for me and gives for example:

> euclid(48, 30);
48, "=", 1, "*", 30, "+", 18
30, "=", 1, "*", 18, "+", 12
18, "=", 1, "*", 12, "+", 6
12, "=", 2, "*", 6, "+", 0
                               6