Can anyone help me with the following two:
1) Can you write a procedure showCol which uses the for var in list do...od construction to print the elements of a list in a column.
showCol([a,b,c]);
2) Write a procedure primeCol which print the primes between given integers m and n in a column.
Thanks.
Homework
These appear to be homework exercises. They are not particularly difficult.
You shouldn't expect us to do your homework for you. What have you tried, and what was the result?
Hint for #2: you will probably find isprime useful.
Closed Door Secrets
Then what should I expect? What is your purpose for being in this forum?
Yes, this is an easy exercise and I am not enrolled in any classes dealing with Maple as you assumed. I figured it out about 2 days after I posted it without any help. I don't have any experience with any programming, but I know not to rely on hidebound individuals. Here is my procedure as requested:
Hint#2: Isprime:= proc(m,n) local i:
for i from m to n do
if type(i,prime) then
print(i); fi;od;
end:
P.S: I don't have problems sharing information with anybody. These are aren't any closed door secrets. Your hints are just an excuse for indolence on your behalf. Maybe you should give a *** for a change.
Code of Conduct
Just a minute, where did I put my flame-retardant keyboard. I haven't had to use it lately, but it's here somewhere.
Found it.
Now, let's look at the Student Help Center Code of Conduct:
Student Help Center code of conduct (Please read!)
Welcome to the Maple Student Help Center. This is a great place to get help on effectively using Maple for your courses. This forum will be supported by Maplesoft staff as well as experienced users around the world. Please take the time to read the following code of conduct:
We reserve the right to remove any posts that do not, in our opinion, fall within the guidelines of conduct for this Web community.
It appears to me that you have not followed three of the first 4 items in this list: obscene, disrespectful, and asking ohers to do your homework. There is no excuse for this. The way you have responded does not make me interested in trying to help you do your homework. There is a big difference IMHO between asking someone to do your homework for you and getting help with your homework.
One reason most of us want to see something that you have done towards your problems is that we want to see the level on which you trying to use Maple. You never told us what type of class this is for, or anything about your background. What version of Maple are you using? These are very important pieces of information I seek to have answered before I answer any question in this forum or in face-to-face interaction with students.
The post that offended you so much did contain some very useful suggestions, which you appear to have chosen to ignore. I'll focus on the second question. Maple has a command, isprime, that returns true if the argument is prime and false otherwise. For example, the following procedure returns all primes between its two arguments:
IP := (m,n) -> select( isprime, [$m..n] );
IP(10,20);
[11, 13, 17, 19]
This implementation does not use any explicit looping. It will be much more efficient than your attempt, but this might not be anywhere close to what you would be expected to understand or come up with on your own.
Doug
Mr. Meade: As far as not
Mr. Meade: As far as not following the three things on the list, where is it that I was obscene? As far as being disrepectful, I don't appreciate smart alec resonpses or assumption made about me. All three of your accusations are greatly exaggerated. I just said that I will not ask anybody with a hidebound attitude for help any longer on this forum, since the last person assumed I was asking for help on my homework such as yourself. First of all, I am not a student. Second, I am not your student either. Third, my reason for being on this forum is because I purchased Maple and was browsing through some of its features. Alas! I stumbled on this site. Lastly, you did not answer my question for # 2 as I stated originally.
P.S: Since I answered my own questions for both #1 and #2, there was no reason for you to write back to me. I do not care to engage in such frivolities nor to cow- tow to your sarcasms. If you have any problems regarding this post, I am sure I can arrange to meet with you in person and discuss these issues.
where you posted
You posted your original questions in one of the "Student Help" forums, and not in one of the non-Student-related "Get Help" or "General Discussion" forums.
Observation
A minor correction. It is not true that explicit looping in Maple is necessarily inefficient. In fact, for the particular task given, which consists of printing a column of primes, most of the time is likely to be spent in the print routine, if not in the primality testing. Note by the way (this is intended for the original poster) that printing, required here, is not something one ordinarily does with Maple. It is usually more effective to return output (say as a list of primes) rather than to print it, since we can further manipulate the output but can do little but look at printed output.
To demonstrate my point about explicit looping not necessarily being inefficient, here are two procedures that return a list of primes, from m to n. The second one, which is essentially what Doug described, is the superior procedure. It is short, clear, and does the job. However, it really is is only marginally faster than the first. The call to time shows the elapsed duration required for each to return all primes from 1 to 100,000.
Here is how I did it
for #1
The list "L" must be define before running showCol.
> showCol := proc (L::list)
local x;
for x in L do
print(L[x]);
end do;
end proc;
> showCol(L);
for #2
> primeCol := proc (m::integer, n::integer)
local L, i;
L := select(isprime, [seq(m .. n)]);
for i to nops(L) do
print(L[i]);
end do;
end proc;
> primeCol(1, 100);
Have you find a shorter way to do it?
mario.lemelin@cgocable.ca
alternative
PrimeCol := proc(m::integer, n::integer) local L; L := select(isprime, [seq(m..n)]); printf("%{t}d\n", Matrix([L])); # ?rtable_printf for details. t transposes. end proc:Yes, but here a more practical ....
... way so you can use the output
mario.lemelin@cgocable.ca
This can be simplified to
primeCol := proc(m::posint, n::posint)Vector(select(isprime, [seq(m .. n)]));
end proc
RETURN
As ?return help page says,
Use of the RETURN procedure is strongly discouraged :)
Alec