Joe Riel

9665 Reputation

23 Badges

20 years, 28 days

MaplePrimes Activity


These are answers submitted by Joe Riel

You could use one of the filters in Signal Blocks > Continuous.  Alternatively, you could build your own from the various blocks.  Feedback works fine; what did you try?

There is a typo, change

if ndisk = 1 then

to

if ndisks = 1 then

Followup

While I was able to spot the error by inspection, a more useful and practical technique is to use a syntax checker. The maplemint procedure can be used for procedures assigned in a worksheet. Here is an example of using it on a simplified version of the original code.

myproc := proc(ndisks) if ndisk = 1 then return; end if; end proc:
maplemint(myproc);
    These names were used as global names, but were not declared: 
      ndisk
    These parameters were never used explicitly: 
      ndisks

The printed message should alert the user that there is a problem with the ndisk usage.

@sigl1982 Here's a first cut at the basic implementation.

Factorization := module()
option object;

local expr        # the expression to factor
    , factors     # its factorization
    , prof := ""  # the profiled output string
    ;

export
    ModuleApply :: static := proc( )
        Object(Factorization, _passed);
    end proc;

export
    ModuleCopy :: static := proc( self :: Factorization
                                  , proto :: Factorization
                                  , ex :: algebraic
                                  , { profile :: truefalse := false }
                                  , $
                                )
        self:-expr := ex;
        if profile then
            debugopts('traceproc' = factor);
        end if;

        self:-factors := factor(ex);

        if profile then
            self:-prof := debugopts('procdump' = factor);
            debugopts('traceproc' = false);
        end if;

    end proc;

    # Return the computed factorization
export
    Factors :: static := proc(self :: Factorization);
        self:-factors;
    end proc;

export
    Profile :: static := proc(self :: Factorization);
        printf("%s", self:-prof);
    end proc;

    # Implement the actual factorization.  Here just call the global factor procedure.
local
    factor :: static := proc(expr)
        :-factor(expr);
    end proc;

end module:

f1 := Factorization(x^3-1, profile);

Factors(f1);
Profile(f1);
# savelib('f1', "f1.mla");

This appears to be an issue with the 2D parser. The simplest workaround is to manually expand the input: Array(1..3,1..3,1..3);

If the node names of your tree structure are always symbols, consider using packed records, rather than tables, as the data structure.  Here I've modified the code to use records.

RecordTest1 := proc(a := NULL, b := NULL)
local aindx, bindx;
    if a::'record' and b::'record' then
        aindx := {exports(a)};
        bindx := {exports(b)};
        aindx = bindx and andmap(i->RecordTest1(a[i],b[i]), aindx);
    else
        evalb(a = b);
    end if;
end proc:

Note that sets have to be used here for the indices, the exports procedure has no indexorder option. With a depth of 6 and width of 10, this ran twice as fast as the table-based version. Constructing the structure is also faster.

Here's a simple recursive test.

TableTest := proc(a := NULL, b := NULL)
local aindx, bindx;
    if a::table and b::table then
        aindx := {indices(a)};
        bindx := {indices(b)};
        aindx = bindx and andmap(i->TableTest(a[op(i)],b[op(i)]), aindx);
    else
        evalb(a = b);
    end if;
end proc:

The immediate issue is that ModuleApply, which is what is called by TestModule(3), returns not a module but the result of a computation.  Modify the procedure to return thismodule.  Also, there is a bug in CodeTools:-Profiling:-PrintProfiles; you can work around it by replacing that line by

printf("%s",debugopts('procdump' = run));

Using modules as dynamic objects is possible, however, the newer Maple construct, an object (implemented as a specialization of a module) is generally better.

Change

ModelSet(1):= Model1;

to

ModelSet(1):= eval(Model1);

See the help page last_name_eval for a discussion of why this is necessary.

A simple way to see understand what happens during parallel transport on a constant latitude of a sphere is to consider parallel transport on the cone that is tangent to the sphere at that latitude. A cone is flat, so the change in angle is equal to the angle of the cut from a flat sheet that is used to form the cone.

One approach is to return the output as a string, then use StringTools:-RegSubs to remove the lhs.

printf("%s", StringTools:-RegSubs("^[^=]*= "="", C(x^2+y^2+z^2,'output=string'))):
x * x + y * y + z * z;

Write V as a vector (not a list). LinearAlgebra:-VectorNorm can be used to compute the norm of the vector.

V := <vx,vy>:
-1/2*C*LinearAlgebra:-VectorNorm(V,2)*V;

Here is one approach

myproc := proc(A,B,C)
local L;
   L := [A,B,C];
   if L :: 'list(algebraic)' then
      # option 1
   elif L :: listlist then
      if numelems(A) = 2 then
          # option 2
      elif numelems(A) = 3 then
          # option 3
      end if;
   elif L :: 'list(Vector)' then
      if numelems(A) = 2 then
          # option 4 (may want to check others for consistency)
      else
          # option 5 (ditto)
      end if;
    else
        error "unknown types of arguments"
    end if;
end proc;

Consider using mtaylor rather than two calls to series.

mtaylor(f(x,y),[x,y],3);

One could use the optional third argument in a call to collect to apply a function to each coefficient of a polynomial.

Directly assigning values, or in this case, lists of values, to variables that are used in the expressions of interest is not generally the best strategy with Maple. More effective is to assign a set of equations that define the numeric values of the variables and then use them to evaluate the expressons. For example

params := [ k = 1, m = 2 ]:
y := k/m^2:
eval(y, params);

Your situation is more complicated in that you have multiple values for each parameter. I assume that you want to evaluate the derived expressions with all parameters taking, say, the second value in their respective lists. You could accomplish that by doing something like

params := [ k = [1,2], m = [2,3] ]:
getparams := proc(k) local eq; [seq(lhs(eq) = op(k, rhs(eq)), eq = params)]; end proc:
eval(y, getparams(2));

You could do

foldl((a,b)->mods(a*b,m),x,y,z);
           mods(mods(x y, m) z, m)
 
First 22 23 24 25 26 27 28 Last Page 24 of 114