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

@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

 

 

@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

 

 

And probably a few changes in the code will make it possible to have the code calculate the appropriate plotting region, so the user don't need to choose it ...

And probably a few changes in the code will make it possible to have the code calculate the appropriate plotting region, so the user don't need to choose it ...

Hi Carl. Your suggestion is very ingenious! It took me a while to understand what is going on. Several of those special commands/signs ($, ~ and zip) are new to me. By trying parts of your expressions, I figured your idea. It is great and works perfectly in the present example. I was however posing a reduced problem, and not the one I am really working on. Firstly the frequencies in the vector B - hence each 0 or positive - can have many digits, so you will need to multiply by say 1000000 or so. It will yield an enormous vector. Of course you could say one will never be able to watch the difference if you take only 4 decimals or so, but the vector A may contain 10000 entrances. Also it would be of interest to have a more safe method. How will you create the lineplot if their are no repetitions in the A vector? I can't even find a command in Maple creating the lineplot when only the frequencies are given and not a list of raw data ...

Erik

5 6 7 8 9 10 11 Last Page 7 of 15