Joe Riel

9610 Reputation

23 Badges

19 years, 182 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Right-click on the combo box (assume it has label ComboBox0), select Edit Select Action and change it to

use DocumentTools in 
  Do(a = %ComboBox0);
end use;

I'm assuming that the combo box holds the values and you want the selected value to be assigned to the global variable a.

I use the following

kerneloptsall := proc( typ :: type := anything
                       , { returnlist :: truefalse := false }
                       , $
                     )
local eq, eqs, fields, maxlen;
    fields := [NULL
               , 'ASSERT'
               , 'assertlevel'
               , 'bindir'
               , 'byteorder'
               , 'bytesalloc'
               , 'bytesused'
               , 'cacheclearlimit'
               , 'cpulimit'
               , 'cputime'
               , 'cputype'
               #, 'dagtag'
               , 'datadir'
               , 'datalimit'
               , 'dirsep'
               , 'display_zero_complex_part'
               , 'filelimit'
               , 'gcbytesavail'
               , 'gcbytesreturned'
               , 'gcfreq'
               , 'gcmaxthreads'
               , 'gcthreadmemorysize'
               , 'gctimes'
               , 'gctotaltime'
               , 'gmpthreshold'
               , 'gmpversion'
               , 'homedir'
               , 'includepath'
               , 'inline'
               , 'jvmheaplimit'
               , 'level'
               , 'limitjvmheap'
               , 'locale'
               , 'mapledir'
               , 'max_record_depth'
               , 'maxdigits'
               , 'maximmediate'
               #, 'memusage'
               , 'multithreaded'
               , 'numcpus'
               , 'numactivethreads'
               , 'opaquemodules'
               , 'pathsep'
               , 'pid'
               , 'platform'
               , 'printbytes'
               , 'printlevel'
               , 'processlimit'
               , 'profile'
               , 'setsort'
               , 'sparse_sort_cutoff'
               , 'stackalloc'
               , 'stacklimit'
               , 'system'
               , 'toolboxdir'
               , 'toolboxversion'
               #, 'unread'
               , 'username'
               , 'version'
               , 'wordsize'
              ];
    eqs := map(proc(fld)
               local val;
                   val := kernelopts(fld);
                   if val :: typ then
                       return fld = val;
                   else
                       return NULL;
                   end if;
               end proc, fields);
    if returnlist then
        return eqs;
    else
        maxlen := max(map(eq -> length(lhs(eq)), eqs));
        for eq in eqs do
            printf("%-*a = %a\n", maxlen, op(eq));
        end do;
        return NULL
    end if;
end proc:

LibraryTools:-Save(kerneloptsall, sprintf("%s/maple/lib/kerneloptsall.mla", kernelopts('homedir')));

The older technique is to use the map procedure. For example,

map(ln, [a,b,c]);

Note that [a,b,c] is a Maple list, not an array. Both map and ~ work on various structures, though map is more general.

  A := Array([a,b,c]):
  ln~(A);
                 [ln(a)  ln(b)  ln(c)]
  map(ln, A);
                 [ln(a)  ln(b)  ln(c)]

Command-Shift-G invokes Greek mode on a Mac. Use Ctrl-Shift-G for Windows or Linux. The next key typed is interpreted as a Greek letter.  See Worksheet,Documenting,2DMathShortCutKeys.

Another route, with a slightly different result, is

seq(curry(`*`,a), a=1..3);   
          () -> `*`(1, args), () -> `*`(2, args), () -> `*`(3, args)

(**) %(x);
                                  x, 2 x, 3 x

I don't know what model you are referring to, however, I'll describe one method, with MapleSim 2016, using the Linearization app.

  1. Put the mechanism of interest in a subsystem, with causal inputs and outputs.  
  2. Open the Linearization app and select the subsystem.
  3. Linearize the subsystem.
  4. Choose the Bode analysis and generate the Bode plot.

I don't know of a good way to do that, using Maple's invztrans procedure. You can get some useful information by tracing the `invztrans/ratpoly` procedure. For example

debug(`invztrans/ratpoly`):
invztrans(z/(z^2+1),z,n);

For the most part, Maple modules cannot be constructed in the way you are attempting, i.e. by doing

Q := module()
export Qdef;
end module:

Qdef := proc(a,b,c,d)
  a + b*I + c*J + d*K;
end proc:

Aside from the issue that I, J, and K appear to be undeclared, the assignment to Qdef must be inside the body of the Qdef module assignment, for example

Q := module()
export Qdef;
    Qdef := proc(a,b,c,d)
        a + b*I + c*J + d*K;
    end proc:
end module:

The usual way to achieve this is do write the code in text files. One can then use $include statements to include a file:

Q := module()
export Qdef;
$include <Qdef.mpl>
end module:

The file Qdef.mpl would then contain the source for Qdef.

One way to do that is to put the assignment in the Maple Initialization file.  See the help page Worksheet,reference,initialization.

A variation is to add the following to the said initialization file

ScientificConstants:-AddConstant( CoulombForceConstant, symbol='k_', derive=1/4/Pi/epsilon[0]):

In a worksheet you could access it as a regular scientific constant.

Running that the maple code you supplied exits immediately as the snr_eff_string variable, etc., is not properly assigned.

Note that a better way to test whether a variable is assigned is to use the 'assigned' procedure.

A problem with your approach is that builds a set by continually appending to it one element at a time; with Maple that is O(n^2) in time and memory.  One way to avoid that is to insert each orbit in a table, as an index, then at the end of the procedure count the number of distinct indices:

   orbits := table();
   ...
   orbits[orbit] := 0;
   ...
   return numelems([indices(orbits,'nolist')]);

With that trivial change the procedure returns the correct result in 12 seconds.

Somewhat surprisingly, the calls to convert(.,base,.) are using much of the remaining time. The computation of d2 should be moved out of the inner loop, no need to recompute it each time. The computation of d3 can be be saved and reused by assigning

base3 := proc(ix)
option remember;
    convert(ix,'base',3);
end proc:

and then using that in the procedure. With that the run time is down to 3 seconds.

The computation of interl can be done in a seq, as can the first computation of orbit. The second computation is trickier to do with a seq.

Consider the generalization of this,

sum(k*i+m,i=1..n)=N;

for k and N fixed and positive. Solving for m gives

m = N/n - (n+1)*k/2

which is monotonic decreasing with n. So if N is odd, the number of unique solutions equals the number of positive divisors of N. In this case, 3375 = 3^3*5^3, so number of divisors is (3+1)*(3+1) = 16.

 isolve(sum(2*(m+i-1)+1,i=1..n) = 3375);

To keep only the solutions with positive n, do

sols := [isolve(sum(2*(m+i-1)+1,i=1..n) = 3375)]:
select(hastype, sols, identical(n) = posint);

The circuit doesn't  make sense.  The 10V source should have its negative side grounded and the positive side connected to the top of both R1 and R3.

If you're serious, you should consider using the emacs maple debugger, available at my github site. The drawback of that is that if you aren't familar with emacs the learning curve will be steep.  The advantage is that with that it is probably quite easy to do what you want.  I would display the stack, which shows up in a buffer with each procedure call on the stack, click on the procedure of interest, which is then displayed in another buffer, set a breakpoint where desired, then click on the call to that procedure, which reexecutes it and stops the debugger at the breakpoint. That isn't guaranteed to work but usually does.  

First 23 24 25 26 27 28 29 Last Page 25 of 114