zenterix

405 Reputation

5 Badges

3 years, 126 days

MaplePrimes Activity


These are replies submitted by zenterix

@tomleslie Sorry about that. I am usually very, very precise, but somehow I feel that Maple allows me to make a lot of mistakes. Perhaps that is just a downside of the power of the symbolic computations that we can do in Maple.

Maple is great, but it's kind of nightmarish when it comes to being able to prototype something quickly that is error-free.  But yes, your version does have the intended result. Let me just thank you two tremendously for the help with this.

The last step would be to save the animation.

I used the commands acer used in your other comments to save to an .m file. I'm not sure about what an .m file is. But reading it worked like a charm.

Garbage is a bit of a strong word. After all, this example (your version) did solve all the issues I had (generating the animations, saving them, and reading them). I don't quite feel like I understand what exactly is happening all the time, but I guess I just have to keep learning about Maple.

PS: How do I run the animations in this editor like you and acer are doing?

@acer Let me come up with a more substantial example worksheet and a more detailed post. I'll post it in an hour or so.

Here is a worksheet exemplifying the issue I am encountering to display my animation using this new way that doesn't use animate: Animation_Test.mw

Here is a summary of what is done in that worksheet

- create a matrix of size 20x3 where each row represents the position of the tip of an arrow

- create a list with the results of calls to plot:-arrow passing in each row in the matrix

- create a list with the results of calls to plots:pointplot3d, representing the "trail" or "path" of the last windowSize points at which the arrow was

- plot the arrow individually; it works. Plot the trail individually; it works

- I'd like to plot both at the same time. My issue at this point is just the syntax of using display to accomplish this, as you can see in the worksheet. I've been trying various variations based on the examples you guys provided, to no avail yet.

- if I can do this, then it means I can save these lists to a file and read them in later and display.

@tomleslie okay, I get it. This looks very promising. I guess plots:-animation is just a wrapper around this very strategy, right?

I will implement this and let you know how it goes.

I am using plots:-animate. This returns a function which I pass to display (in reality I have five such functions animating different things, and they are all sent to display to get the final animation). How would you save such a function?

For a bit more context, the solution to the system of differential equations is a trajectory on the surface of a sphere. I also compute a window of the last N points in this trajectory so this is also animated. I also have another trajectory representing something else. These trajectories are the tips of arrows that start at the center of the sphere and they are also animated.

I managed to save one of the animations as a gif using Export, but did not manage to Import it yet.

UPDATE: I also managed to save an animation as a gif using plottools:-exportplot. I suppose I could save all five animations this way in a directory and then import them and display them. Not sure if this is smart or if there is a better way though.

UPDATE 2: But one of the things I want to save, the sphere, isn't an animation. It's just a call to plottools:-sphere which generates some result that when I print it out says MESH. Not sure what this is but I can't save it as a gif like for the animations.

@acer 

This works very well for, well, a Matrix (or a Vector with ExportVector). 

Truth be told, however, what I actually want to save is the result of calling plots:-animate. This is not a Matrix. The error I get when I try to save this thing is

Error, (in QComputing:-computeAndSaveAnimationData) invalid input: ExportMatrix expects its 2nd argument, M, to be of type {Matrix, list(Matrix)}, but received [PLOT3D(ANIMATE([CURVES(Matrix(1, 3, [[-0.,-0.,-1.]], datatype = float[8])), TITLE(t = 1.)],[CURVES(Matrix(2, 3, [[-0.,-0.,-1.],[-.0009668681546,.01893805236,-.9998206506]], datatype = float[8])), TITLE(t = 2.)],[CURVES(Matrix(3, 3, [[-0.,-0.,-1.],[-.0009668681546,.01893805236,-.9998206506],[-.003871386882,.03871964562,-.9992439148]], datatype = float[8])), TITLE(t = 3.)],[CURVES(Matrix(4, 3, [[-0.,-0.,-1.],[-.0009668681546,.01893805236,-.9998206506],[-.003871386882,.03871964562,-.9992439148],[-.008739819788,.05805870882,-.9982765367]], datatype = float[8])), TITLE(t = 4.)],[CURVES(Matrix(5, 3, [[-0.,-0.,-1.],[-.0009668681546,.01893805236,-.9998206506],[-.003871386882,.03871964562,-.9992439148],[-.008739819788,.05805870882,...

Looks like there are various Matrices inside this bit data structure.

Any idea how to save this?

In reality I have a sphere, and then four animations. The latter are two arrows from the center of the sphere to its surface, plus the path traced out by the tips of the arrows. 

Right now, I'm keeping the four results of calls to plots:-animate and the call to plottools:-sphere in a list and I call plots:-display to display them all together in one animation.

I'd like to generate the data for the entire thing (the list of five things), and save this. When I read the list, I just call display and pass the list.

@mmcdara 

I want to solve a system of differential equations that depends on a set of stochastic parameters. Basically, this means that every time I solve I will get a slightly diifferent solution.

In general terms, to accomplish this what I do is run a procedure using Grid package. 

The procedure contains the call to dsolve. I run the procedure N separate times using Grid package's Map procedure for parallelization. From each run I obtain an output which is essentially the result of dsolve.

Then I average them and plot them. This is all done in a worksheet.

I'd like to have this entire process be executed in a batch file. Ie, run the Grid:-Map command that I am using to run the procedure in a batch file, and each procedure saves its output to a file. Then later on (after the long time it takes to run the procedures), I can simply read the files and make the plots.

I think the specific application (solving this system of differential equations) is secondary to the main question I have which is: in general, what is the best way to save results of computations to be used later on in a different session or worksheet?

@acer How is this

"Side-note: You can also programatically create a self-installing file which unpacks any or all of .mla, .help, source, and build-scripts to the equivalent directory on someone else's machine. (This knows where to place these toolbox files regardless of operating system: Linux, MS-Windows, or OSX.)"

done by Maple?

@Joe Riel 

I'm used to big JavaScript projects with thousands of files and a variety of flavors of organizing those files.

I've asked here before about what people do to organize their files and to improve their workflow and productivity. I'm still converging on what my ultimate workflow in Maple will be, but my initial approach is to have each .mla file together with the other files that are associated with it. This way I can use .git and share with my collaborators.

The reason I want to modify libname programatically is so that I can create new projects and not have to manually change the initialization file.

I am aware that some keep all .mla files in one single location and this means they don't touch the initialization file. That's fine, I'm just trying a different way to see if it works.

The repository I linked seems to have a working package that does what I expect. In particular: add a path to libname in the initialization file, remove any path (by index) from the initialization file, and save a package contained in an .mpl file to an .mla file.

The workflow becomes:

1) create a new project directory (or clone a newly created github repo)

2) call addPathToLibname(projectDirectory) 

3) create one or more .mpl files that define packages

4) call savePackageToMla(mlaPath, mplPath, packageName)

5) use the saved package from any worksheet using with or use

6) after code for a package has been modified, call savePackageToMla(mlaPath, mplPath, packageName)

7) since the .mla file is part of the directory, someone else can clone the repo, call addPathToLibname(projectDirectory), and they can use the package in their worksheets

We need to use the option 'overwrite' with FileTools:-Open, as follows

FileTools:-Text:-Open(mapleInitFile, 'overwrite'):

I read about it here.

@acer I will try to be more careful to not post inaccurate commands that I am using. 
In fact, mplPath and mlaPath use double quotes, so no problem there.

I have to confess something. At this point, it does work but I am not sure anymore what the issue was.

@acer I have a few questions here. Multiple things I am unaware of.

- You said that you only have the top src directory in the include-path. Are you referring to the libname path? From what you wrote, that top src contains mpl files. The "include path" I am aware of is related to libname, which looks for mla files as far as I know. Shouldn't it rather be the lib folder that is in the "include path"?

- What is an .mm file?

- I am assuming that you keep .mla files in a lib directory because Maple can find them there? I've read about this behavior concerning lib folders, but haven't been able to replicate it.

- any example repository? The link you sent of Maple Cloud has a list of "projects/packages?" and when I download they come as a .maple file, yet another file type I am not sure about what it represents.

EDIT: so I looked a bit on Github and here is a repository where the author has included the files that "build" the project.

The file basically creates an .mla file on the fly, defines a module that includes tons of other files and exports a ton of stuff, and in the end saves the module to the .mla file.

It would really make things easier if .mla in lib were part of the libname search path.

@Ronan 

How did you find Sublime Text? I've never really used it before.

At some point like two years ago I was using Vscode, and I just googled and found this plugin which looks promising. I'll check it out later today.

Also will check out this jEdit that I've never heard of before.

@Carl Love 

I'm not really sure if what you say is correct about the error.

The first of the two worksheets I sent you has the code

module NumberGenerator()    
option object;    
local defaultSeed;      
defaultSeed:=100;        

export setSeed:=proc(newSeed)          
defaultSeed:=newSeed:      
end proc:

export getSeed:=proc()          
return defaultSeed:      
end;

end;

If I insert a "code edit region" in the same worksheet, and simply copy and paste the problematic module code that isn't being parsed, then it works.

Here is an updated worksheet example with the code edit region: Number_Generator_Module.mw

@tomleslie 

Let me tell you a bit of the context of why I am asking this question to address some of your comments.

I am helping a researcher with the programming aspect of a problem in quantum physics. I don't understand the physics nor much about the specific differential equations. Let me address some of your comments directly

Here is the worksheet you sent updated with some missing parts (like a procedure gen): OPevents2.mw

1) the reason I am setting method, abserr, and relerr is that in the original problem using the classical method always works, but we want to use rkf45 but dsolve did not work for this method without setting the other two parameters. Recently I asked a question where I posted a simplified version of the issue

But basically, to summarize, there are two differential equations and they are each defined with a stochastic multiplicative term. This seems to mess with the error correction of dsolve with rkf45. The solution I found was to set the abserr and relerr.

In the worksheet I posted in the current question, i(x) is supposed to be a way to access a discrete variable in the differential equations at each iteration step. I would like to be able to know which iteration we're on. With this information I can access data from, say, a matrix. This is just one strategy to speed up obtaining the stochastic terms I mentioned earlier.

2) as for the specific syntax you addressed, consider the following

events = [[0, 2 - x<0], [i(x) = i(x) + 1]]

As far as I can tell from the documentation, this is the following in the documentation

So I was just trying to tell Maple: if x>2 in any iteration, then trigger the event and the action is to increment i by 1.

4 5 6 7 Page 6 of 7