Carl Love

Carl Love

27229 Reputation

25 Badges

11 years, 346 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are questions asked by Carl Love

Why have there been so many old Posts and Questions moving to the top of the Active Conversations stack the past two days, even though they have no new activity? This makes MaplePrimes very difficult to use! Please make it so that the Active Conversations stack is sorted by the actual time of the most-recent addition to the thread.

This Question involves using dsolve(..., numeric) for an IVP specifed by a procedure. This is based on a Question asked earlier today. In this Question, I have no interest in how to solve this IVP or in why this solution technique fails. In the worksheet below, the odeplot command seems to get stuck in an infinite loop (I am not interested in why that happens), and I press the stop button (in the Standard GUI). Then, instead of the usual Warning, computation interupted message followed by a return to the command prompt, I get an informative message and the plot that has been computed so far. This seems like a very useful feature: to return the results computed so far after an interuption. Furthermore, those results are programmatically accessible. My Question is How is this done? How do you trap the stop button and return the results?


restart:


Sys:= proc(N,t,Y,YP)

local eqs,yp2,yp4;

     YP[1]:= Y[2];

     YP[3]:= Y[4];

     eqs:= [
          yp2*Y[3]+yp4*Y[2]*sin(Y[1]^2)+cos(yp4*Y[3]) = sin(t),
          Y[2]*yp4*sin(Y[1]*Y[3])+5*yp2*Y[4]*cos(Y[1]^2)+t^2*Y[1]*Y[3]^2 = exp(-Y[3]^2)
     ];

     YP[2],YP[4]:= op(subs(fsolve(eqs,{yp2=1,yp4=2}),[yp2,yp4]))

end proc:

res:= dsolve(
     numeric, procedure= Sys, initial= Array([1,1,2,2]),
     number= 4, procvars= [x1(t),diff(x1(t),t),x2(t),diff(x2(t),t)],
     start= 0, maxfun= 0
):

 

plots:-odeplot(res, [t,x1(t)], 0..0.27);
#After 10 seconds or so, (I did)/(you should) hit the stop button.

Warning, cannot evaluate the solution further right of .25109286, cannot downgrade delay storage for problems with delay derivative order > 1, try increasing delaypts

#Note that the command's result is still programmatically accessible:

P:= %;

PLOT(CURVES(Array(1..201, 1..2, {(1, 1) = .0, (1, 2) = 1.0, (2, 1) = 0.135e-2, (2, 2) = 1.001349729199153, (3, 1) = 0.27e-2, (3, 2) = 1.0026989169868508, (4, 1) = 0.405e-2, (4, 2) = 1.004047563645964, (5, 1) = 0.54e-2, (5, 2) = 1.005395669456049, (6, 1) = 0.675e-2, (6, 2) = 1.0067432346933451, (7, 1) = 0.81e-2, (7, 2) = 1.0080902596307788, (8, 1) = 0.945e-2, (8, 2) = 1.0094367445379593, (9, 1) = 0.108e-1, (9, 2) = 1.0107826896811836, (10, 1) = 0.1215e-1, (10, 2) = 1.01212809532343, (11, 1) = 0.135e-1, (11, 2) = 1.0134729617243639, (12, 1) = 0.1485e-1, (12, 2) = 1.0148172891403349, (13, 1) = 0.162e-1, (13, 2) = 1.0161610778243784, (14, 1) = 0.1755e-1, (14, 2) = 1.0175043280262126, (15, 1) = 0.189e-1, (15, 2) = 1.0188470399922427, (16, 1) = 0.2025e-1, (16, 2) = 1.020189213965557, (17, 1) = 0.216e-1, (17, 2) = 1.0215308501859302, (18, 1) = 0.2295e-1, (18, 2) = 1.0228719488898206, (19, 1) = 0.243e-1, (19, 2) = 1.0242125103103719, (20, 1) = 0.2565e-1, (20, 2) = 1.0255525346774133, (21, 1) = 0.27e-1, (21, 2) = 1.0268920222174571, (22, 1) = 0.2835e-1, (22, 2) = 1.0282309731537027, (23, 1) = 0.297e-1, (23, 2) = 1.0295693877060321, (24, 1) = 0.3105e-1, (24, 2) = 1.0309072660910137, (25, 1) = 0.324e-1, (25, 2) = 1.0322446085219004, (26, 1) = 0.3375e-1, (26, 2) = 1.0335814152086296, (27, 1) = 0.351e-1, (27, 2) = 1.0349176863578238, (28, 1) = 0.3645e-1, (28, 2) = 1.0362534221727904, (29, 1) = 0.378e-1, (29, 2) = 1.037588622853522, (30, 1) = 0.3915e-1, (30, 2) = 1.0389232885966946, (31, 1) = 0.405e-1, (31, 2) = 1.0402574195956709, (32, 1) = 0.4185e-1, (32, 2) = 1.041591016040497, (33, 1) = 0.432e-1, (33, 2) = 1.0429240781179057, (34, 1) = 0.4455e-1, (34, 2) = 1.044256606011312, (35, 1) = 0.459e-1, (35, 2) = 1.0455885999008183, (36, 1) = 0.4725e-1, (36, 2) = 1.04692005996321, (37, 1) = 0.486e-1, (37, 2) = 1.0482509863719582, (38, 1) = 0.4995e-1, (38, 2) = 1.0495813792972193, (39, 1) = 0.513e-1, (39, 2) = 1.0509112389058335, (40, 1) = 0.5265e-1, (40, 2) = 1.0522405653613263, (41, 1) = 0.54e-1, (41, 2) = 1.0535693587831985, (42, 1) = 0.5535e-1, (42, 2) = 1.0548976192244952, (43, 1) = 0.567e-1, (43, 2) = 1.0562253468268996, (44, 1) = 0.5805e-1, (44, 2) = 1.0575525417260814, (45, 1) = 0.594e-1, (45, 2) = 1.058879204046671, (46, 1) = 0.6075e-1, (46, 2) = 1.0602053339022601, (47, 1) = 0.621e-1, (47, 2) = 1.0615309313954047, (48, 1) = 0.6345e-1, (48, 2) = 1.0628559966176196, (49, 1) = 0.648e-1, (49, 2) = 1.0641805296493847, (50, 1) = 0.6615e-1, (50, 2) = 1.0655045305601394, (51, 1) = 0.675e-1, (51, 2) = 1.0668279994082868, (52, 1) = 0.6885e-1, (52, 2) = 1.06815093624119, (53, 1) = 0.702e-1, (53, 2) = 1.0694733410951756, (54, 1) = 0.7155e-1, (54, 2) = 1.0707952139955317, (55, 1) = 0.729e-1, (55, 2) = 1.0721165549565084, (56, 1) = 0.7425e-1, (56, 2) = 1.0734373639813168, (57, 1) = 0.756e-1, (57, 2) = 1.074757641062132, (58, 1) = 0.7695e-1, (58, 2) = 1.0760773861800887, (59, 1) = 0.783e-1, (59, 2) = 1.0773965993052852, (60, 1) = 0.7965e-1, (60, 2) = 1.078715280396781, (61, 1) = 0.81e-1, (61, 2) = 1.0800334294025973, (62, 1) = 0.8235e-1, (62, 2) = 1.081351046259718, (63, 1) = 0.837e-1, (63, 2) = 1.082668130894088, (64, 1) = 0.8505e-1, (64, 2) = 1.0839846832206155, (65, 1) = 0.864e-1, (65, 2) = 1.0853007031431687, (66, 1) = 0.8775e-1, (66, 2) = 1.08661619055458, (67, 1) = 0.891e-1, (67, 2) = 1.0879311453366416, (68, 1) = 0.9045e-1, (68, 2) = 1.0892455673601087, (69, 1) = 0.918e-1, (69, 2) = 1.0905594564846983, (70, 1) = 0.9315e-1, (70, 2) = 1.0918728125590897, (71, 1) = 0.945e-1, (71, 2) = 1.0931856354209235, (72, 1) = 0.9585e-1, (72, 2) = 1.0944979248968028, (73, 1) = 0.972e-1, (73, 2) = 1.0958096808022917, (74, 1) = 0.9855e-1, (74, 2) = 1.097120902941917, (75, 1) = 0.999e-1, (75, 2) = 1.098431591109168, (76, 1) = .10125, (76, 2) = 1.0997417450864941, (77, 1) = .1026, (77, 2) = 1.1010513646453082, (78, 1) = .10395, (78, 2) = 1.1023604495459853, (79, 1) = .1053, (79, 2) = 1.1036689995378606, (80, 1) = .10665, (80, 2) = 1.1049770143592332, (81, 1) = .108, (81, 2) = 1.1062844937176912, (82, 1) = .10935, (82, 2) = 1.1075914369810387, (83, 1) = .1107, (83, 2) = 1.108897843678326, (84, 1) = .11205, (84, 2) = 1.1102037134210607, (85, 1) = .1134, (85, 2) = 1.1115090457860155, (86, 1) = .11475, (86, 2) = 1.1128138403152263, (87, 1) = .1161, (87, 2) = 1.1141180965159976, (88, 1) = .11745, (88, 2) = 1.1154218138608973, (89, 1) = .1188, (89, 2) = 1.1167249917877577, (90, 1) = .12015, (90, 2) = 1.118027629699678, (91, 1) = .1215, (91, 2) = 1.1193297269650222, (92, 1) = .12285, (92, 2) = 1.1206312829174188, (93, 1) = .1242, (93, 2) = 1.1219322968557623, (94, 1) = .12555, (94, 2) = 1.123232768044212, (95, 1) = .1269, (95, 2) = 1.1245326957121933, (96, 1) = .12825, (96, 2) = 1.1258320790543948, (97, 1) = .1296, (97, 2) = 1.1271309172307735, (98, 1) = .13095, (98, 2) = 1.1284292093665487, (99, 1) = .1323, (99, 2) = 1.1297269545522062, (100, 1) = .13365, (100, 2) = 1.131024151843497, (101, 1) = .135, (101, 2) = 1.1323208002614376, (102, 1) = .13635, (102, 2) = 1.133616898792309, (103, 1) = .1377, (103, 2) = 1.1349124463876585, (104, 1) = .13905, (104, 2) = 1.1362074419642976, (105, 1) = .1404, (105, 2) = 1.137501884404303, (106, 1) = .14175, (106, 2) = 1.1387957725550182, (107, 1) = .1431, (107, 2) = 1.1400891052290492, (108, 1) = .14445, (108, 2) = 1.1413818812042709, (109, 1) = .1458, (109, 2) = 1.1426740992238196, (110, 1) = .14715, (110, 2) = 1.1439657579960996, (111, 1) = .1485, (111, 2) = 1.1452568561947796, (112, 1) = .14985, (112, 2) = 1.1465473922561644, (113, 1) = .1512, (113, 2) = 1.1478373642224777, (114, 1) = .15255, (114, 2) = 1.14912677047606, (115, 1) = .1539, (115, 2) = 1.1504156093257876, (116, 1) = .15525, (116, 2) = 1.1517038789853584, (117, 1) = .1566, (117, 2) = 1.1529915775732906, (118, 1) = .15795, (118, 2) = 1.1542787031129238, (119, 1) = .1593, (119, 2) = 1.1555652535324183, (120, 1) = .16065, (120, 2) = 1.1568512266647548, (121, 1) = .162, (121, 2) = 1.1581366202477354, (122, 1) = .16335, (122, 2) = 1.1594214319239837, (123, 1) = .1647, (123, 2) = 1.1607056592409424, (124, 1) = .16605, (124, 2) = 1.1619892996508772, (125, 1) = .1674, (125, 2) = 1.1632723505108726, (126, 1) = .16875, (126, 2) = 1.1645548090828357, (127, 1) = .1701, (127, 2) = 1.165836672533493, (128, 1) = .17145, (128, 2) = 1.1671179379343934, (129, 1) = .1728, (129, 2) = 1.1683986022619053, (130, 1) = .17415, (130, 2) = 1.169678662397219, (131, 1) = .1755, (131, 2) = 1.1709581151263448, (132, 1) = .17685, (132, 2) = 1.172236957140115, (133, 1) = .1782, (133, 2) = 1.1735151850341814, (134, 1) = .17955, (134, 2) = 1.174792795282732, (135, 1) = .1809, (135, 2) = 1.1760697835893776, (136, 1) = .18225, (136, 2) = 1.1773461457270373, (137, 1) = .1836, (137, 2) = 1.1786218774884782, (138, 1) = .18495, (138, 2) = 1.179896974422449, (139, 1) = .1863, (139, 2) = 1.181171431833682, (140, 1) = .18765, (140, 2) = 1.182445244782893, (141, 1) = .189, (141, 2) = 1.1837184080867809, (142, 1) = .19035, (142, 2) = 1.1849909163180268, (143, 1) = .1917, (143, 2) = 1.1862627638052967, (144, 1) = .19305, (144, 2) = 1.1875339446332376, (145, 1) = .1944, (145, 2) = 1.1888044526424812, (146, 1) = .19575, (146, 2) = 1.1900742814296414, (147, 1) = .1971, (147, 2) = 1.1913434243473158, (148, 1) = .19845, (148, 2) = 1.1926118745040841, (149, 1) = .1998, (149, 2) = 1.193879624764512, (150, 1) = .20115, (150, 2) = 1.195146667749144, (151, 1) = .2025, (151, 2) = 1.1964129956664247, (152, 1) = .20385, (152, 2) = 1.1976785994686407, (153, 1) = .2052, (153, 2) = 1.1989434702227826, (154, 1) = .20655, (154, 2) = 1.2002075985381981, (155, 1) = .2079, (155, 2) = 1.2014709744148189, (156, 1) = .20925, (156, 2) = 1.2027335872431564, (157, 1) = .2106, (157, 2) = 1.2039954258043046, (158, 1) = .21195, (158, 2) = 1.2052564782699382, (159, 1) = .2133, (159, 2) = 1.2065167322023145, (160, 1) = .21465, (160, 2) = 1.2077761745542712, (161, 1) = .216, (161, 2) = 1.2090347916692288, (162, 1) = .21735, (162, 2) = 1.2102925692811892, (163, 1) = .2187, (163, 2) = 1.2115494925044938, (164, 1) = .22005, (164, 2) = 1.2128055446540236, (165, 1) = .2214, (165, 2) = 1.2140607079057624, (166, 1) = .22275, (166, 2) = 1.2153149635677838, (167, 1) = .2241, (167, 2) = 1.216568291442756, (168, 1) = .22545, (168, 2) = 1.2178206698279472, (169, 1) = .2268, (169, 2) = 1.2190720755152231, (170, 1) = .22815, (170, 2) = 1.2203224837910482, (171, 1) = .2295, (171, 2) = 1.221571868436484, (172, 1) = .23085, (172, 2) = 1.22282020172719, (173, 1) = .2322, (173, 2) = 1.224067453329788, (174, 1) = .23355, (174, 2) = 1.225313589366023, (175, 1) = .2349, (175, 2) = 1.226558573530251, (176, 1) = .23625, (176, 2) = 1.227802365810496, (177, 1) = .2376, (177, 2) = 1.229044922475539, (178, 1) = .23895, (178, 2) = 1.2302861960749185, (179, 1) = .2403, (179, 2) = 1.2315261354389295, (180, 1) = .24165, (180, 2) = 1.2327646837576534, (181, 1) = .243, (181, 2) = 1.2340017760538164, (182, 1) = .24435, (182, 2) = 1.2352373405616506, (183, 1) = .2457, (183, 2) = 1.2364712973589982, (184, 1) = .24705, (184, 2) = 1.2377035562942194, (185, 1) = .2484, (185, 2) = 1.2389340149185948, (186, 1) = .24975, (186, 2) = 1.2401625575137232, (187, 1) = .2511, (187, 2) = undefined, (188, 1) = .25245, (188, 2) = undefined, (189, 1) = .2538, (189, 2) = undefined, (190, 1) = .25515, (190, 2) = undefined, (191, 1) = .2565, (191, 2) = undefined, (192, 1) = .25785, (192, 2) = undefined, (193, 1) = .2592, (193, 2) = undefined, (194, 1) = .26055, (194, 2) = undefined, (195, 1) = .2619, (195, 2) = undefined, (196, 1) = .26325, (196, 2) = undefined, (197, 1) = .2646, (197, 2) = undefined, (198, 1) = .26595, (198, 2) = undefined, (199, 1) = .2673, (199, 2) = undefined, (200, 1) = .26865, (200, 2) = undefined, (201, 1) = .27, (201, 2) = undefined}, datatype = float[8], order = C_order), COLOUR(RGB, .47058824, 0., 0.54901961e-1)), AXESLABELS(t, x1))

``


Download trap_stop_button.mw

There are no examples for ModuleDeconstruct either on its help page or in the Programming Guide. Of course, I can figure out its basic and primarily intended purpose: to render the module/object in a one-dimensional plaintext printed form, which would be useful for debugging. But I am most interested in this use described in the second sentence of this, the second paragraph of Description at ?ModuleDeconstruct [italics added]:

When the value returned by ModuleDeconstruct is printed, the output could be capable of being parsed to the original module. When used with an object, ModuleDeconstruct can return an unevaluated call to a constructor to achieve this.

That seems very powerful. Is there any example of it being used in Maple library code? in user code? Can anyone here come up with a practical use for this? A Google search turns up nothing.

Can anyone tell me what is going on in the following worksheet? 


restart:

 

The following type  matches any second-or-higher-order derivative specified in D form with independent variables. You don't need to understand how this type works---which is, admittedly, convoluted---in order to understand the rest of this post.


TypeTools:-AddType(
     HODD,
     {typefunc(
           name,
           typefunc(
                name,
                {'`@@`'(identical(D), posint),
                 And(specindex(posint, D), satisfies(D-> nops([op(D)]) > 1))
                }
           )
      )
     }
);

 

Here's an expression which is simply a sum of various types of derivatives. Note that the first and last terms only differ in the dependent variable name.


expr:=
     D[1,2](u)(x,t) + diff(u(x,t), x, t) + diff(f(x),x$2) +
     diff(f(t),t) + (D@@3)(f)(x) + D(g)(x) + D[1,2](v)(x,t)
;

(D[1, 2](u))(x, t)+diff(diff(u(x, t), t), x)+diff(diff(f(x), x), x)+diff(f(t), t)+((D@@3)(f))(x)+(D(g))(x)+(D[1, 2](v))(x, t)

I1:= indets(expr, HODD);

{(D[1, 2](u))(x, t), (D[1, 2](v))(x, t), ((D@@3)(f))(x)}

The above result is as expected: Ds of order greater than 1 are selected; diffs are not. Now I try to extract the diffs also.

 

indets(expr, HODD &under (convert, D));

{diff(diff(f(x), x), x), diff(diff(u(x, t), t), x), (D[1, 2](v))(x, t), ((D@@3)(f))(x)}

The above result is missing D[1,2](u)(x,t) even though it contains the syntactically identical term D[1,2](v)(x,t)! Running trace  on `type/&under` shows that it never gets called for that missing term! So, the problem is not in &under. A further test shows that if the missing term is put elsewhere in expr (after restart, of course) then the indets works okay.

 

The following result is even weirder. One would expect that for any types T1 and T2 and any expression expr, that indets(expr, {T1, T2}) would equal indets(expr, T1) union indets(expr, T2), right? One would expect that even if there were a bug with one of the individual indets calls, right? So, note that I1 above contains the first term of expr, yet ...

indets(expr, {HODD, HODD &under (convert, D)});

{diff(diff(f(x), x), x), diff(diff(u(x, t), t), x), (D[1, 2](v))(x, t), ((D@@3)(f))(x)}

I get the same results if put the type explicitly in the indets calls rather than using AddType. I get the same results in Maple 16 and 18. So, what's going on?

 


Download indets.mw

How do I convert a hardware float to a software float? I have a procedure that is passed floats as arguments. They could be hardware or software floats. I need to set an attribute on these floats (with setattribute). Trying to use setattribute on a hardware float produces utterly bizarre results, although, strangely, not an error. But I'd be happy converting them to software floats and then setting the attribute. I tried (separately)

UseHardwareFloats:= false;

convert(x, float, 16);

SFloat(op(x));

And, FWIW, here's the procedure, although I doubt that it'll provide any more useful information than I've already given. Note that in this procedure I've redefined log to be the base-10 logarithm. (Not that that makes the slightest difference wrt my Question.)

LogView:= proc(viewspec::{range, identical(DEFAULT)}, Range::range)
local aV, bV, aP, bP, aL, bL;
     (aP,bP):= op(map(x-> 10^x, Range)); # The actual range of the ORIGINAL plot structure
     if viewspec = 'DEFAULT' then
          setattribute(op(1,Range), aP) .. setattribute(op(2,Range), bP)
     else
          (aV,bV):= op(viewspec); #The user-specified view in the pre-log units
          if bV <= 0 then error "upper view limit must be positive; received %1.", bV fi;
          (aL,bL):= op(Range); #Actual range of the log plot structure
          setattribute(`if`(aV >= aP, log(aV), aL - (aP-aV)/(min(bP,bV)-aP)*(log(min(bP,bV))-aL)), aV) 

          .. setattribute(`if`(bV <= bP, log(bV), bL + (bV-bP)/(bP-max(aP,aV))*(bL-log(max(aP,aV)))), bV) 

     end if
end proc;

In the specific use instance that I'm dealing with, the first parameter, viewspec, is DEFAULT, and the second, Range, is HFloat(-43.42...)..HFloat(43.42...).

I think the ideal solution would be to use parameter coercion to convert the arguments.

4 5 6 7 8 9 Page 6 of 9