Carl Love

Carl Love

24342 Reputation

25 Badges

9 years, 357 days
Natick, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Here's another way to do the unit conversion on a vector or matrix that I suspect is closer to what you were originally trying. Enter your vector, highlight and right click, do the unit conversion as you originally tried. When that's done, the vector will appear unchanged, as you initially reported. Now, give the command

rtable_eval(%);

The unit-converted vector should now appear.

The issue here is somewhat like the rtablesize issue that I wrote about an hour ago in the sense that the computations are already done but you're not seeing the results; however, in this case the issue doesn't only affect the display. (It took me many years to fully understand the rtable_eval command, so you'll likely need to just accept that it's the "magic command" that does what you want in this case.)

What you described is indeed an efficient (although somewhat mysterious) way to fill a matrix. It doesn't matter whether the entries are floats or any other type. The key step is to use the very mysterious command rtable_eval on the row vector; it changes the symbolic variables (ABC, etc.) in the row vector to their assigned values. Like this:

restart:
OutVec:= <A, B, C>^%T: #row vector
OutMat:= Matrix((9, numelems(OutVec)), datatype= anything):
#The datatype could be hfloat or anything else or omitted entirely.

MyFuncs:= proc(k)
    :-A:= (k-1)^2;
    :-B:= k^2;
    :-C:= (k+1)^2;
    rtable_eval(OutVec)
end proc
:
for k to upperbound(OutMat)[1] do
    OutMat[k]:= MyFuncs(k)
od
:
OutMat;

Whether you send this matrix to Excel afterwards is irrelevant; that'd be handled exactly like sending any matrix to Excel, e.g., as shown by @dharr .

I can't tell you how to do it with context-menu-based commands such as you appear to be using, but these text-based commands do it:

convert~(<20., 30., 40.>*Unit(MPa), units, psi);
convert~(<150., 300., 600.>*Unit(psi), units, MPa);

Note the ~ after convert, which causes the command to be applied elementwise to the vector. It works exactly the same for a matrix, array, list, set, or table.

What you describe should be fairly easy because Maple (since Maple 2018) has an on-board Python interpreter and a small package of commands to support it. See help page ?Python.

It's easier to write a procedure for this that works for an arbitrary number of arguments than it is to write one specific to 4 arguments. In the procedure below, you'll need to fill in the ...'s.

biggest4:= proc(S::seq(realcons)) #i.e., the arguments will be a SEQuence of REAL CONStants
local 
    M:= S[1], #Initialize max to 1st argument (arbitrarily).
    x #any of the arguments
;
    #Compare every argument to the max computed so far and adjust it if needed:
    for x in S do
        #The "is" command is sometimes needed to compare complicated symbolic
        #expressions that represent real numbers:
        if is(x > ...) then ...:= ... fi 
    od;
    M #procedure's return value
end proc
:
biggest4(-1/3, 0, 7/3, -2);

If you omit the is, this'll still work for these example numbers.

I'm sure that you know the standard techniques, so I wonder why they're working for me but not for you:

S:= select(type, [solve](diff(F,z), z), realcons);
allvalues(S[min[index](eval~(F, z=~ S))]);

 

@mehdibgh It should come as no surprise that fff has some negative values. So, sqrt(fff) has some imaginary values. To check, extract the min and max values from the data matrix of a plot of fff (not sqrt(fff)):

(min, max)(op([1,3], plot3d(fff, zeta__1= -1..1, eta__1= -1..1)));
              -1.68517697876451*10^(-7), 0.000874224224310557

So the negative values have relatively small magnitude, but they are there nonetheless. If fff has been constructed to be positive valued, then these negatives are from rounding errors in the huge number of floating-point calculations. In this case, just ignore the imaginary parts.

I'm amazed that anyone finds these imaginary parts surprising!

1) Plotting them all: This can be done by using plots:-display on a matrix of individual plots.

2) Finding equivalence classes (under graph isomorphism or any other property): This can be done with ListTools:-Categorize; or, if you know a function that gives an equivalence class representative, it can be done more efficiently with ListTools:-Classify.

# This likely only works in 1D-input!
#
DrawGraphs:= (L::{list,set}(Graph))->
local n:= nops(L), c:= isqrt(n);
    (plots:-display@Matrix)(
        (ceil(n/c), c), 
        (i,j)-> local k:= (i-1)*c+j; 
            if k<=n then GraphTheory:-DrawGraph(L[k], 'title'= k, _rest)
            else plot('axes'= 'none')
            fi
    ):   
n:= 50:
LG:= ['GraphTheory:-RandomGraphs:-RandomGraph(6,7)' $ n]:
ListTools:-Categorize((i,j)-> GraphTheory:-IsIsomorphic(LG[i],LG[j]), [$1..n]);
# Indices in each sublist represent isomorphic graphs.
[1, 11, 14, 15, 18, 19, 23, 24, 36, 38], [2, 41, 47, 50], [3, 5], 
  [4, 13, 44, 46], [6], [7, 12, 25, 33, 39, 49], [8], [9, 27], 
  [10, 29], [16], [17, 40], [20, 31, 34], [21, 42], 
  [22, 28, 30, 32, 48], [26], [35], [37], [43], [45]

DrawGraphs(LG);

 

To avoid the dialogs regarding the axis names, you can set environment variables like this:

_Env || (Horizont, Vertic) || alName:= (x, y):

This only needs to be done once per session (per restart), and it doesn't matter whether you do it before or after with(geometry) or whether you use with(geometry) at all. If you use geometry a lot, and you always use x and as the coordinates, then it's worth putting that command in an initialization file. On the other hand, if you often use a variety of coordinate names, then you should use Christopher's Answer.

I avoid the problem of double-quotes inside of double-quotes and the need to use backslash escaping by using back-quotes for the outermost (only!) quotes of the nprintf command:

cprint:= curry(nprintf, `#mo("%s",mathcolor="%a");`):
cprint("This is green", green);

                 This is green

cprint("This is green", red);
                 
This is green

As far as I can tell, the value of interface(typesetting) has no effect on this; however, the value of interface(prettyprint) must be 2 or 3.

Use your operating system to kill the kernel. When it's killed (which almost always happens instantly), you'll have a chance to save and close your worksheet and reopen it in another kernel. If you're using Windows, and need specific details, I can provide them.

Is there some reason that you used the undocumented and very inefficient goto rather than the a simple
proc() do print(1) od end proc():
?

It's a good thing that you suppressed the output with a colon. If you hadn't, you'd have a much bigger problem killing it. In that case, you need to kill the GUI, which kills everything, allowing you to save nothing.

Here's another way to create the transformation T and its matrix with respect to the given basis B:

restart:
Coeffs:= (e::algebraic, V::list(name))->
local t, C:= coeffs(collect(e, V, 'distributed'), V, t), T:= table(sparse, [t]=~[C]);
    t-> T[t]
:
V:= [x,y]:
T:= e-> eval(e, V=~ ([1,-1]*~(sqrt(3)*y)-~x)/2):
B:= <seq(mul(V^~[4-i, i]), i= 0..4)>:
M:= `<|>`(seq(Coeffs(T(b), V)~(B), b= B)); 

Your titular "difficulty with concatenation and indexing" is quite simply that concatenation cannot be used as a substitute for indexing by a variable (or for any other form of parameterization).

Your code can be simplified to the following; there is no need for any packages:

restart:
theta:= 2*Pi/17:
plot(
    [cos,sin]~([$0..16]*~theta), 
    style= point, symbol= solidcircle, color= red, symbolsize= 10
);

 

Wrap the command with lprint(...):

Gp:= GroupTheory:
lprint(Gp:-Generators(Gp:-SmallGroup(60,10)));

[Perm([[1, 2], [3, 8], [4, 9], [5, 10], [6, 12], [7, 11], [13, 23], [14, 24], [
15, 26], [16, 25], [17, 28], [18, 27], [19, 30], [20, 29], [21, 32], [22, 31],
[33, 44], [34, 43], [35, 46], [36, 45], [37, 48], [38, 47], [39, 50], [40, 49],
[41, 52], [42, 51], [53, 58], [54, 57], [55, 60], [56, 59]]), Perm([[1, 3], [2,
8], [4, 13], [5, 14], [6, 15], [7, 16], [9, 23], [10, 24], [11, 25], [12, 26],
[17, 33], [18, 34], [19, 35], [20, 36], [21, 37], [22, 38], [27, 43], [28, 44],
[29, 45], [30, 46], [31, 47], [32, 48], [39, 53], [40, 54], [41, 55], [42, 56],
[49, 57], [50, 58], [51, 59], [52, 60]]), Perm([[1, 4, 5], [2, 9, 10], [3, 13,
14], [6, 17, 19], [7, 18, 20], [8, 23, 24], [11, 27, 29], [12, 28, 30], [15, 33
, 35], [16, 34, 36], [21, 39, 41], [22, 40, 42], [25, 43, 45], [26, 44, 46], [
31, 49, 51], [32, 50, 52], [37, 53, 55], [38, 54, 56], [47, 57, 59], [48, 58, 
60]]), Perm([[1, 6, 21, 22, 7], [2, 11, 31, 32, 12], [3, 15, 37, 38, 16], [4, 
17, 39, 40, 18], [5, 19, 41, 42, 20], [8, 25, 47, 48, 26], [9, 27, 49, 50, 28],
[10, 29, 51, 52, 30], [13, 33, 53, 54, 34], [14, 35, 55, 56, 36], [23, 43, 57,
58, 44], [24, 45, 59, 60, 46]])]

I used copy-and-paste to transfer that output to MaplePrimes. Yes, it's slightly different from the original display, but perhaps acceptable to you.
 

You've entered your proposed solution as 

1/root(cos(x)^2 * 8*cos(x)-3 * sin(x),3)

You're missing parentheses in that. The actual solution is

1/root(cos(x)^2*(8*cos(x) - 3*sin(x)), 3)

This can be shown to be equivalent to dsolve's solution. That's not difficult to do, but not trivial either.

First 8 9 10 11 12 13 14 Last Page 10 of 356