Joe Riel

9500 Reputation

23 Badges

18 years, 128 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Depends on what you want to do with the data structure.  Maple tables and MultiSets behave quite differently. 

The foldl procedure can be used to generate the expression

foldl(((o,k)->1+z^k/o),1,seq(7..1,-1)); 

In Maple2021 you can use the fold option to seq

seq[fold=(((o,k)->1+z^k/o),1)](7..1,-1);

Try the following
 

Y := Ym*(c/((d + 1)*(X - X__0) + c))^(d + 1)*exp((X - X__0)*(d + 1)^2/((d + 1)*(X - X__0) + c)):
Xsol := solve(Y = Ym/2, X):
simplify(Xsol);
                1/(d+1)*(d*X__0+X__0-c-1/LambertW(-2^(-1/(d+1))*exp(-1))*c)

 

A simple approach is to convert to a ZeroPoleGain form of transfer function and then truncate all poles and zeros greater than some arbitrary frequency.  That may give acceptable results if the frequencies of the truncated poles and zeros are much greater than the dominant ones.

Alas, in the Graph plotting returns, non-integer weights are printed as floats using sprintf("%0.3g", weight).  That should probably be modified.  There is a hack that you can use.  The idea is to temporarily replace the sprintf function with your own version, one which arbitrarily repaces any use of "%0.3g" as the format string with "%a".  Here's how you do so
 

unprotect(sprintf):
oldsprintf := eval(sprintf):
# temporarily replace sprintf with ad hoc version
sprintf := proc(fmt) oldsprintf(ifelse(fmt="%0.3g","%a",fmt),_rest); end proc:
# create the plot
P := (DrawGraph)(G, style=tree, root=Omega,size=[400,400]):
# restore sprintf
sprintf := eval(oldsprintf):
r := plottools:-rotate(P, Pi/4);

If you plan to draw several graphs, you might create your own procedure that incorporates this hack.

MyDrawGraph := proc()
global sprintf;
local oldsprintf;
    unprotect('sprintf');
    oldsprintf := eval(sprintf);
    sprintf := proc(fmt) oldsprintf(ifelse(fmt="%0.3g","%a",fmt),_rest); end proc;
    try
        return GraphTheory:-DrawGraph(_passed);
    finally
        sprintf := eval(oldsprintf);
        protect('sprintf');
    end try;
end proc:

 

For a Matrix of floats, you can map the round function to each element:

N := map(round, data);

However, by default, Import returns a DataFrame with an Array of type datatype=float[8], and mapping over that will leave the datatype=float[8], so the result still appears to be floats. You may need to first convert the data to a Matrix. Alternatively you can use the output option to Import to specify a Matrix, then map over that:

data := Import("foo.xlsx", 'output=Matrix'):
data := map(round, data);

 

It's not entirely clear what you want. Regardless, use a loop with a conditional such as

if StringTools:-RegMatch("\\.edu$", M[i,1]) then ... end if

to test the string in row 1, column 1 of the imported Matrix.

A few comments. 

  1. There is no type 'real' in Maple.  Maybe you want 'float', or 'realcons'.
  2. Adding a type declaration to procedure output (here the ' :: real) has no effect unless kernelopts(assertlevel) is set to 2 (the default is 0).
  3. A semicolon is used as a separator in the local statement; change it to a comma.
  4. Profiling won't work if an error is raised.

One way to profile the local Test2 (assuming the divide-by-zero statement is removed) is to do so inside Test.  For example

Test := proc(a,b)
local c, Ergebnis;
    Test2 := proc(d,e) #Prozedur zum Schreiben der Ausgaben
        f:=d+e;
        g:=f*d;
        5+3;
        # 3/0;
    end proc:
    debugopts('traceproc'=Test2);
    c:=a+b;
    Ergebnis := Test2(a,c);
    printf("%s\n", debugopts('procdump'=Test2)):
end proc:

Test(3,4);

One way to find an error is with the debugger, say first execute stoperror(all) then call Test.  That should cause the debugger to open at the offending statement. Alas, that won't help here because the error occurs during simplification, as the zero in the denominator is hard-coded into the source and so the error is raised when the procedure is assigned, not when it is executed.

There is a workaround for this.  You can create a data file of sampled random noise and use it in a time-table interpolation block to generate the noise source.  This is conveniently done via the MapleSim app in Utility > Random Data.  Select the distribution and the relevant parameters, generate the data and attach it (save it), then add a time table component and select the attached data as the source.  Here is a simple example, NormalNoise.msim

Insert a multiplication sign (*) after the epsilon. Without it, Maple is interpreting it as a function call.

The 'tran' output of Syrup:-Solve is a set of differential equations.  The usual way to handle this is to pass them to dsolve and then use that solution, with the others to solve for specific variables.  For example

(volts,others) := Solve(ckt,'tran', 'returnall');
dsol := dsolve(volts);
# substitute others, and then dsol, into i[R1](t), then take its derivative
diff(subs(others, dsol, i[R1](t)), t);

 

Using mint, Maple's syntax checker, is helpful. Because it works with external source files, an alternative is to use maplemint. For example
 

(**) foo:=proc(expr)
(**)   local x;
(**)   map(x->x^2,expr);
(**) end proc:
(**) maplemint(foo);
Procedure foo( expr ) 
  These local variables were never used:  x

 

Is Ti the sampling period?  Regardless, for now the easiest way to handle this is to either construct the model graphically, using discrete components, or to write Modelica code for the model.  I've taken the latter approach. See DigitalControl.msim. Double click on the dig model to open a Modelica editor that displays its code.

What type of joint?  A multibody rotational joint?  It has a builtin damping constant.  For other types of friction you can connect a 1D rotational device between the two 1D rotational ports on the multibody rotational joint.

The installation command is wrong (it is different in the zip file than what you show). The correct command is
 

PackageTools:-Install("this://", overwrite)

The incorrect one used backslashes, not forwardslashes.

First 7 8 9 10 11 12 13 Last Page 9 of 114