d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Programming Assignment Help > Language: Maple
Add Reply New Topic New Poll
Member
Posts: 20,261
Joined: Dec 31 2008
Gold: 67.15
Feb 1 2016 06:13pm
Asked a friend for help and he's never heard of it, probably 'cause Maple is a Canadian programming language I guess, anyways not so much looking for someone to tell me what to do but more to check that I'm on the right track.
I'm using Maple 17 for this assignment.

I got only 4 questions to do and I think I've got 2 of them good.

Q.1 Find product of the square root of all prime numbers less than 100.

z := 1:
for i from 1 to 100 do
k := isprime(i);
if k = true then
print(i);
z := z*i
end if;
end do:
print(z);

For this I got it to list all the prime numbers less than 100 and calculate the product, but I don't yet know how to add in the square root.

Q.2 Find the sum of all odd composite numbers less than 150.

y := 0:
for i from 1 to 150 do
a := i mod 2;
if a = 1 then
b := isprime(i);
if b = false then
print(i);
y := y+i
end if;
end if;
end do:
print(y);

I'm sure this one is correct, followed the form of a sample question from class.

Q.3 Find the sum of the first 30 powers of 2.

Really not sure how to go about this one, I can do 2^30 of course (assumed that's what it means by "30 powers of 2"), but don't know how to set it up so that it sums up all the individual powers.

Q.4 Find the sum of all odd numbers between 50 and 100.

x := 0:
for i from 50 to 100 do
c := i mod 2;
if c=1 then
print(i);
x := x+1
end if;
end do:
print(x);

I'm also sure this one is correct, same as Q.2 minus the composite numbers.
Member
Posts: 20,261
Joined: Dec 31 2008
Gold: 67.15
Feb 1 2016 08:46pm
Update: I've figured out (somewhat) all the answers I need, not going to post any in case there are certain people looking to see if answers are posted, thread can be closed.

Also if anyone is well versed in Maple, would be nice if you could PM me to help me out with future things, should I need any (will also try to get some FG to make it worth your while (if necessary)).
Thanks
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 1 2016 09:27pm
i dont know maple, but it looks pretty straight forward. just post your questions here. i'm not downloading any software, so either you can run it or find an online interpreter.
Member
Posts: 20,261
Joined: Dec 31 2008
Gold: 67.15
Feb 15 2016 06:23pm
Quote (carteblanche @ 1 Feb 2016 22:27)
i dont know maple, but it looks pretty straight forward. just post your questions here. i'm not downloading any software, so either you can run it or find an online interpreter.


Got a new question right now, seems simple enough, just can't figure it out the way I need it done

Question:
Write a Maple procedure, LCM, which takes as input n>0 integers a1, a2, a3, ... an and computes their least common multiple.

This is the best way I can think of writing it

MyProc := proc(a,b,c)
lcm(a,b,c);
end proc

When executing it, i.e.
MyProc(1,2,3);

it gives 6

But according to the question it wants the input as a list of (n) variables and not a set amount (like the 3 that I defined)
Not sure how to go about using a list as input
Member
Posts: 12,427
Joined: Mar 4 2006
Gold: 5,077.00
Feb 15 2016 08:29pm
It can't be this simple, think about cases for n=2 and n>2 the equation differs so for n=2 we know lcm(a,b)=ab/gcd(a,b)
But for n>2
Lcm(a1,a2,...,an)= lcm((lcm(a1,a2),a3,...,an)

Hope this leads you in the correct way, I learned mathematica and not maple in my program so I can't give you exact syntax but split it into two cases and it should be simple from there. Sorry if quality isn't best im typing in phone.


Edit no just define a as a vector of length n

A = vector of length n
N=length of vector
If n<=2
Lcm(a1,a2) = (a1a2)/gcd(a1,a2)
Else
Lcm(a1,a2,...,an)= lcm((lcm(a1,a2),a3,...,an)

This post was edited by Xx Shin3d0wn xX on Feb 15 2016 08:55pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 15 2016 08:29pm
brief google search shows you can use a list or sequence:
http://www.maplesoft.com/support/help/Maple/view.aspx?path=exprseq
using them in a param:
http://www.maplesoft.com/support/help/maple/view.aspx?path=parameter_modifiers#seq

have you tried something like so:

MyProc := proc(s::seq(numeric))
ilcm(s);
end proc

MyProc(1,2,3);

This post was edited by carteblanche on Feb 15 2016 08:31pm
Member
Posts: 20,261
Joined: Dec 31 2008
Gold: 67.15
Feb 15 2016 11:53pm
Quote (carteblanche @ 15 Feb 2016 21:29)
brief google search shows you can use a list or sequence:
http://www.maplesoft.com/support/help/Maple/view.aspx?path=exprseq
using them in a param:
http://www.maplesoft.com/support/help/maple/view.aspx?path=parameter_modifiers#seq

have you tried something like so:

MyProc := proc(s::seq(numeric))
ilcm(s);
end proc

MyProc(1,2,3);


ah cool, that works
thing is, is that I don't even know what means or how it works (as in it hasn't been covered in class yet)
referring to the s::seq(numeric) and ilcm(s)

I also have to write comments and stuff explaining what each line does and I'm not sure what to do with this xD

i'm guessing ilcm= integer lcm?
and s::seq is just assigning s to a numeric sequence input?
basically?

thanks :D

This post was edited by Agonist on Feb 16 2016 12:02am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 16 2016 07:09am
Quote (Agonist @ Feb 16 2016 12:53am)
ah cool, that works
thing is, is that I don't even know what means or how it works (as in it hasn't been covered in class yet)
referring to the s::seq(numeric) and ilcm(s)

I also have to write comments and stuff explaining what each line does and I'm not sure what to do with this xD

i'm guessing ilcm= integer lcm?
and s::seq is just assigning s to a numeric sequence input?
basically?

thanks :D


there might be other ways of doing it. this just happens to be what i found within a few min of research. lcm might work instead of ilcm. i've never used maple so you'd have to try it yourself. when i did a google search of lcm, i found a matrix lcm which i discarded and a polynomial lcm, which sounds like what you tried. i found ilcm and the documentation mentioned "sequence" with as many inputs as you wanted: http://www.maplesoft.com/support/help/Maple/view.aspx?path=igcd

the mention of "sequence" is what made me google for sequence in parameters, which provided the link i gave before:
Quote
The seq modifier allows the parameter to match multiple arguments. When a parameter with a declared type of seq(memberType) is encountered, it consumes all arguments starting from the next available one until an argument not of type memberType is encountered.


i just combined that with your existing code sample to come up with my snippet.

you may be able to use a list or array instead of a sequence. i dont know what you covered in class. you can google for examples of them if you're familiar with them.
Go Back To Homework Help Topic List
Add Reply New Topic New Poll