Mac Dude

1167 Reputation

16 Badges

8 years, 44 days

MaplePrimes Activity


These are replies submitted by Mac Dude

@tomleslie That is exactly the way to do it! I hit onto this last night also, but I wasn't on MaplePrimes so didn't see your suggestion until now. In fact, for nargs=0 (i.e. no argument to density) one can return the graphite value & remain consistent with the normal behaviour of the package. Sweet! My own version ended up looking like this:

ModifyElement('C',density=[value=proc() if nargs=0 then 2.2\
                                        elif args[1]='graphite' then 2.2\
                                        elif args[1]='diamond' then 3.5\

                                        else error "unknown allotrope" end if end proc]);

and

GetValue(Element('C',density));
GetValue(Element('C',density(diamond)));
GetValue(Element('C',density(graphite)));

                             2200.0
                             3500.0
                             2200.0

(the returned numbers are in kg/m^3 due to the SI system whereas the entries in ModifyElement are in g/cm^3.)

Thanks much,

Mac Dude

@dharr Actually, what I am really doing is to add the radiation length X__0 (from a separate table I generated) to the properties of the elements. Radiation length (which is the lengths scale for radiative energy loss of electrons or photons passing through matter) is customarily given in g/cm^2, so to get the actual length one needs to divide X__0 by the density. The cases I am looking at involve crystalline materials including carbon, hence the interest in diamond.

That said, I discovered in the properties help page you referenced that the density already uses a parametrized form for gaseous substances. I am not quite sure why; but in principle it should be possible to program this such as to allow density(graphite) and density(diamond). I can probably do this myself.

Thanks,

M.D.

 

 

@Christopher2222 Thanks much; but no go: Maple won't let me add another element 6 and I can also not chose, say, 1006 for the atomic number in AddElement and then use C for the element symbol (besides, it would be pretty ugly).

So I think I am stuck here :-(. Maybe I'll submit a feature SPR.

Thanks dharr also; the specific comment in Help had escaped me. I actually do not argue with Maple's choice of the allotrope (graphite is more stable  than diamond, which will become graphite if heated up too high [in an inert atmosphere, lest it burns] so don't try to bake your diamonds).

 

Mac Dude.

 

@acer This was actually a sinister thing: There seemed to be funny non-printing chara's at the beginning of each line (and not a Unix vs DOS vs MacOs line-ending thing). Emac would not display them even when I set the relevant toggle to make it show all characters; but hexdump would. For once, good old OS X Textedit would strip the crap when I used it to save the file as ASCII. On top there was a trailing space after each element symbol which convert would preserve & upset ModifyElement. parse strips it and works.

It is what one gets when copy-pasting text out of a pdf.

Anyway, it all works now. Thanks a lot.

M.D.

@acer Wow, I feel dumbfouded. I looked at the file using Emacs since I was wondering about that, and I did not see the extra character. It is a bit weird that it survives the parse procedure. Of course, this is not a Maple problem.

Anyway, will check this out soonest & see if the loop now works.

Thanks much,

M.D.

@acer Ok, here is my attempt at a minimum working example exhibiting the problem. One Maple worksheet and one txt file with the table.

Thanks

Mac Dude

ModifyElementMWE.mw   Radiation_Length_Table.txt

@Carl Love I tried both parse(), and cat('',elemt) per Joel's suggestion. parse() gives the same error; cat fails when the first entry is an empty name. Do note that I also tried convert(elemt,'name') to explicitly make this not a string but a name (my code snippets in the original post may be a bit misleading in this regard).

When doing lprint of the result there is in fact one pair of left quotes.

ModifyElement definitely will not accept a string as element name, and complain as such.

Tx,

M.D.

 


One use-situation that comes to mind is remote access. If you are halfway across the world and want to run a Maple session, say, on your work computer the cli can be a lifesaver. Running X11 remotely is usually not a lot of fun, as is VNC if you can even use it.

M.D.

@edahl Another option worth investigating is the maplev mode for Emacs, by Joe Riel (who is no stranger to this forum). You will need to use emacs, obviously, but it may be worth it. Joe keeps maplev up-to-date for Maple from V to present. maplev does keyword coloring, indentations, will help you sorting out the various end do, end proc etc. closures, and many more things. I believe you can also run Maple from within emacs through it although I am not doing that.

To make this work you create your code as a file with a .mpl extension. Then you "read()" it into Maple.

Just my $0.02.

M.D.

@Carl Love Thanks for the correction. I now use your code above (thanks!) & reran the example. Qualitatively the results are quite similar; probably because I ran the whole For loop in between MU and DeltaMU.

I am now looking at the Programming Guide to figure out what it is I have. Most of them as as I said before, BINARY, which off-hand does not seem to be too helpful.

Still diggin'

M.D.

@Carl Love and acer: Ok, I tried kernelopts(memusage). Indeed it produces output, but I am not much the wiser for it.

The code allocated about 390 MB per the indicator at the bottom of the sheet. If I add all the third entries from the list of lists I get about a quarter of the allocation (95 MB vs 390 MB). The biggest piece with about 67 MB is called BINARY. Which is fine except that I don't really know what this is. It is not floats; I get about 350kB of FLOATs which seems ok. I get about 21000 HASH objects, which seems strange.

I then tried Profile on a specific procedure (one which I suspect maybe at fault). The output is

PrintProfiles(ALU:-BoosterFRamp);
BooSynch:-ALU:-BoosterFRamp
BooSynch:-ALU:-BoosterFRamp := proc(t)
local t__loc, dppdt, momRamp, corrRamp, fRamp;
     |Calls Seconds  Words|
PROC | 7058   2.540 17580262|
   1 | 7058   0.082 317283| fRamp := `if`(assigned(BooSynch:-ALU:-Fc),BooSynch:-f__Bi-BooSynch:-alpha__p*BooSynch:-f__Bi*(momRamp+corrRamp),BooSynch:-f__Bi-BooSynch:-alpha__p*BooSynch:-f__Bi*momRamp);
   2 | 7058   0.038     30| if assigned(BooSynch:-ALU:-t__Start) then
   3 | 7041   0.031 209427|     t__loc := `if`(0 < BooSynch:-ALU:-time_to_inj_act,t-BooSynch:-ALU:-time_to_inj_act-BooSynch:-ALU:-t__Start,t-BooSynch:-ALU:-time_to_inj-BooSynch:-ALU:-t__Start);
   4 | 7041   0.015  28164|     dppdt := BooSynch:-dpp__e/BooSynch:-t1;
   5 | 7041   1.770 12513390|     momRamp := 1/2*dppdt*BooSynch:-t1*piecewise(t__loc < 0,0,0 <= t__loc and t__loc <= BooSynch:-t1,1-cos(t__loc/BooSynch:-t1*Pi),BooSynch:-t1 < t__loc,2);
   6 | 7041   0.522 3982698|     corrRamp := BooSynch:-ALU:-Fc*piecewise(t__loc < 0,0,0 <= t__loc and t__loc <= BooSynch:-t1,1/2-1/2*cos(2*t__loc/BooSynch:-t1*Pi),BooSynch:-t1 < t__loc,0);
   7 | 7041   0.080 529270|     fRamp := `if`(assigned(BooSynch:-ALU:-Fc),BooSynch:-f__Bi-BooSynch:-alpha__p*BooSynch:-f__Bi*(momRamp+corrRamp),BooSynch:-f__Bi-BooSynch:-alpha__p*BooSynch:-f__Bi*momRamp)
                            else
   8 |   17   0.000      0|     fRamp := BooSynch:-f__Bi
                            end if;
   9 | 7058   0.002      0| return fRamp

The number of Calls seems high; there are only 200 direct calls from the loop but I can see that there are a number of indirect calls in each pass. The number of seconds (& I assume the first one is the total time) means this is not where the code spends its time (this run took several minutes). The number of "Words" is puzzling: does this refer to allocated storage? In 64-bit words?? 17 MWords would be a lot; I have no clue where that would be done.

Is this stuff documentd somewhere? The help file barely shows the output and has no real explanation (unless I am so dense that I do not understand the obvious).

Thanks anyway, making some progress but not there yet.

M.D.

@torabi Oh, so you want to do this numerically.

How do you expect to get a numeric solution when you only spec. your initial values as finite?

To have any chance you will need to put in actual values.

I tried to see if a general symbolic solution exists, and Maple returns a solution with new variables and a reduced de. Unfortuntely I don't have time to see if this can be pursued further, but the solution will be quite complicated in any case.

So, find values for your conditions & plug them in to allow for numeric solution.

M.D.

moadele_asli2_(2).mw

It sounds like you really have an initial-value problem. I would use dsolve to get the general solution first. Then you eval your u(r) and the differential expression at r=0; you may equate them to u0 and du0 or whatever you call your initial values. Presumably you have a 2nd-order system so you will have two constants which Maple will call _C1 and _C2. You can then solve these two equations for your initial conditions, which gives you the expressions for _C1 and _C2 in terms of the initial values.

To be more specific we'd have to see your DE. Mere condition that your initial values be finite may not be enough to find the particular solution. If you have a pole at r=0 you may end up with both _C1 and _C2 having to be 0 and the trivial solution.

M.D.

@Pascal4QM Thanks for the link to Joe Riel's elisp debugger. However, the thread is from 2012. I wonder whether Joe could chime in here as to whether that code is still being maintained.

Mapke's debugger is a bit rough around the edges. In most cases I avoid the debugger and just sprinkle print() statements in my code until I get it to run as intended. For large monolithic procs and loops that crap out after some number of cycles I have at times stored intermediate results in tables to be read later.

I should check out Joe's debugger. I like and use his maplev.el code editor a lot.

Thanks again,

M.D.

@Carl Love indeed.

M.D.

2 3 4 5 6 7 8 Last Page 4 of 38