erik10

I have a degree in Mathematics and Physics from the Danish University Aarhus, comparable to a masters degree with thesis - majoring in Mathematics. In 1991-92 I was a visting scholar at UCLA, Los Angeles, following graduate courses in Applied Mathematics. Since 1992 I have been a teacher in a high school (gymnasium) in Denmark. Special interests: Applied mathematics, graphics and popularizing Mathematics.

MaplePrimes Activity


These are replies submitted by erik10

Thanks for your suggestions, Carl. I did use your:

boxVector:= Vector(Size, fill= [], datatype= list(integer)):

and it works. The fun thing is that if I commented it out, it also worked. It didn't a while ago, before I made some changes in the code. Sometimes it works without any feedback from Maple, sometimes I get a blue comment from Maple, which I think is trying to tell me that I should declare a variable, even though my code was executed correctly. Then sometimes I receive a red response from Maple, in which case my code fails to be executed. I tried commenting out some of my other declarations just to see. Some of them resulted in a failure, some of them not. I am really confused, I have to say. I don't see any logic at all, but obviously you guys do ;)

Erik 

 

Still another way to do it. I think I must have overlooked something myself ;)

Great to see in how many ways it can be done.

Erik

Still another way to do it. I think I must have overlooked something myself ;)

Great to see in how many ways it can be done.

Erik

Absolutely great! Thanks to both of you. I like all the different solutions and I have saved them for the future use too.

Erik

@Carl Love Thanks a lot! I have made the changes you advice me to. And in fact it works now! I had to also replace the sum command with an add command, because I received an error. The Help menu for that command say that the index i used in that command is local to the command. With the sum command it interfered with something outside ... Execution time for n = 40, k = 6 is 55 seconds on my machine.

A_recursive_procedur.mw

 

I downloaded your own code for the more efficient way, but reexecuting it created an error message. It is supposed to be easy to resolve - an unexpected ) - but I could not find any parenthesis problem, although I went through the code pretty thoroughly. It is absolutely great that Maplesoft has introduced code coloring in version 17. I hope the next thing will be coloring the line, in which the error occurs. It will often save a lot of time in debugging! Maybe you can quickly point out the problem?

Another thing: Carl, could you explain in words what the overall idea with this Module approach is? What is the benefits of using a Module and how do the Maple compiler handle the code. Only overall.

Erik

@Carl Love Thanks a lot! I have made the changes you advice me to. And in fact it works now! I had to also replace the sum command with an add command, because I received an error. The Help menu for that command say that the index i used in that command is local to the command. With the sum command it interfered with something outside ... Execution time for n = 40, k = 6 is 55 seconds on my machine.

A_recursive_procedur.mw

 

I downloaded your own code for the more efficient way, but reexecuting it created an error message. It is supposed to be easy to resolve - an unexpected ) - but I could not find any parenthesis problem, although I went through the code pretty thoroughly. It is absolutely great that Maplesoft has introduced code coloring in version 17. I hope the next thing will be coloring the line, in which the error occurs. It will often save a lot of time in debugging! Maybe you can quickly point out the problem?

Another thing: Carl, could you explain in words what the overall idea with this Module approach is? What is the benefits of using a Module and how do the Maple compiler handle the code. Only overall.

Erik

Carl, I think I need to reveal what my "do something here" is all about. I guess you will need that information to optimize your code. I did write these details into my initial simple code, because I want to see the difference in execution time between your code compared and mine. Without it we will not know how efficient it is!

Unfortunately I still have some troubles writing my own code, because I am still new to programming in Maple. I get an error message. I am unsure what to declare before the procedure. Also I am unsure if I should use global variables? After execution of the procedure, I want two large Vectors 'probVector' and 'lambdaVector' to be available outside this procedure. Maybe I should initially call the procedure with those two large vectors with zeroes? And then forget about the global variable?

Another thing: I am using Vectors here, but could also use lists maybe? What is the most efficient?

I would be very delighted if you would please tell me the minor changes which will make my own code work. Then we will know about execution times for my code, and then compare how much faster your code will execute!

I appreciate your help!

Here is my new code: A_recursive_procedur.mw

 

Erik 

 

Carl, I think I need to reveal what my "do something here" is all about. I guess you will need that information to optimize your code. I did write these details into my initial simple code, because I want to see the difference in execution time between your code compared and mine. Without it we will not know how efficient it is!

Unfortunately I still have some troubles writing my own code, because I am still new to programming in Maple. I get an error message. I am unsure what to declare before the procedure. Also I am unsure if I should use global variables? After execution of the procedure, I want two large Vectors 'probVector' and 'lambdaVector' to be available outside this procedure. Maybe I should initially call the procedure with those two large vectors with zeroes? And then forget about the global variable?

Another thing: I am using Vectors here, but could also use lists maybe? What is the most efficient?

I would be very delighted if you would please tell me the minor changes which will make my own code work. Then we will know about execution times for my code, and then compare how much faster your code will execute!

I appreciate your help!

Here is my new code: A_recursive_procedur.mw

 

Erik 

 

@Carl Love Actually to be completely detailed I want two lists of real numbers. Each time the computer arrives at a box combination two real numbers are being calculated from the box combination information. One of the numbers are actually a probability, but just think of it as a real number. You ask about if the order matters. Well it does not as long as the two real numbers associated with the same box combination have the same position in either of the two lists. No, I don't need to be able to reconstruct the box combination from the two lists, and the order in which they appear doesn't matter - except the pairing! I hope this makes sense?

Erik

@Carl Love Actually to be completely detailed I want two lists of real numbers. Each time the computer arrives at a box combination two real numbers are being calculated from the box combination information. One of the numbers are actually a probability, but just think of it as a real number. You ask about if the order matters. Well it does not as long as the two real numbers associated with the same box combination have the same position in either of the two lists. No, I don't need to be able to reconstruct the box combination from the two lists, and the order in which they appear doesn't matter - except the pairing! I hope this makes sense?

Erik

Great Carl! I was aware of the problem with memory, because when the computer makes it's way through the recursive procedure it need to hold all information on it's way! So I assume you need to choose the iterative method if the number of boxes is too large. Maybe you need to know a bit more about my "do something here". Here I mean that when the computer has arrived at a certain state corresponding to a box combination, say [10,5,8,9,0,8] - meaning 10 marbles in box 1, 5 marbles in box 2, etc - then the information about this combination should be available, so that a third quantity: som function of the box combination can be calculated. In the end I wish as output a list of the results of having applied the real-valued function to every box combination:

List = [f([40,0,0,0,0,0]), f([39,1,0,0,0,0]), ... , f([0,0,0,0,0,40])]

I will look closer at your code. Thanks a lot!

Erik

Great Carl! I was aware of the problem with memory, because when the computer makes it's way through the recursive procedure it need to hold all information on it's way! So I assume you need to choose the iterative method if the number of boxes is too large. Maybe you need to know a bit more about my "do something here". Here I mean that when the computer has arrived at a certain state corresponding to a box combination, say [10,5,8,9,0,8] - meaning 10 marbles in box 1, 5 marbles in box 2, etc - then the information about this combination should be available, so that a third quantity: som function of the box combination can be calculated. In the end I wish as output a list of the results of having applied the real-valued function to every box combination:

List = [f([40,0,0,0,0,0]), f([39,1,0,0,0,0]), ... , f([0,0,0,0,0,40])]

I will look closer at your code. Thanks a lot!

Erik

I like your link to the Mathematica page. Apparently they already have the command I am requesting. I realize my expression "Line graph" means something completely different, haha.

Your suggestion is pretty much what I am requesting as a built-in command in Maple. Thanks!

 

I like your link to the Mathematica page. Apparently they already have the command I am requesting. I realize my expression "Line graph" means something completely different, haha.

Your suggestion is pretty much what I am requesting as a built-in command in Maple. Thanks!

 

@Alejandro Jakubi Your suggestions for a solution are very smart, but I think rather few Maple users can sort out a solution themselves easily. I consider you guys here experts! I just think it is very basic to have a command that given a list of DIFFERENT numbers (outcomes) with a corresponding list of frequencies plots a linegraph (What is it called in English?). As it seems to be now, it is rather hard to produce a linegraph unless you have raw data. I mean it seems artificial to have to use the CURVES thing, which is intended for another purpose. But it is necessary here. Just my opinion.

I know my request that the list can have repetitions is a complication that you cannot expect to be supported. If the basic command was present, I would probably make a loop running through my list of outcomes to produce a new list with different elements (probably in n^2 time) and then apply the basic command to plot it. 

Erik

 

 

First 6 7 8 9 10 11 12 Last Page 8 of 17