Joe Riel

9660 Reputation

23 Badges

20 years, 3 days

MaplePrimes Activity


These are answers submitted by Joe Riel

UCS := proc(d,e)
local ab;
    ab := {[0, 0], [1, 1], [0, 2], [1, 3], [0, 4], [1, 5], [0, 6], [1, 0], [0, 1], [1, 2], [0, 3], [1, 4], [0, 5], [1, 6], [0, 0]};
    map(chrem, ab, [d,e]);
end proc:

UCS(2,11);
              {0, 1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 15, 16, 17}
Note that I used a set for ab. That ensures that the output contains unique elements. Another approach is to use a list and then remove duplicates. With that approach you may want to explicitly sort the results; that may not be necessary with a set since, for small integers, the results are automatically sorted:
UCS := proc(d,e)
local ab;
uses ListTools;
    ab := [[0, 0], [1, 1], [0, 2], [1, 3], [0, 4], [1, 5], [0, 6], [1, 0], [0, 1], [1, 2], [0, 3], [1, 4], [0, 5], [1, 6], [0, 0]];
    sort(MakeUnique(map(chrem, ab, [d,e])));
end proc:
It would be a lot easier if you just pasted the code into your post.
Practically, I do what Axel does, I use t0. However, because one of the goals of the document interface is to be able to generate presentation quality output, there should be a relatively convenient way to use the subscripted variable in the display. I don't consider palette selection for something as common as subscripts to be convenient; a keyboard shortcut is called for. Note that there is a shortcut for generating a prefixed subscript: 0t. That can be done from 2D input by typing t Ctrl-Shift-_ 0. Considering that prefixed subscripts are rare beasts, it would have been better if that generated a literal subscript (suffixed subscript). Maybe there is a short cut, but I don't know what it is (I found that one by trial and error). Similarly, t Ctrl-Shift-^ 0 produces 0t. A literal suffixed superscript (t0) would be more useful.
Another way to do this, even less practical than my previous suggestion, is to convert the base symbol (t) in the indexed name (t0) to a local variable. Use a macro to make this less slightly less impractical:
macro(t0 = convert(t,`local`)[0]):
int(t0, t);
              t0 t
The reason that the first doesn't display properly is that Maple's standard gui doesn't automatically display arrays (or Arrays) whose indices don't start at one. The simple way to get around that is to make it a Matrix (whose indices always start at one). That is do
EBO := Matrix(11,1):
...
EBO[s+1,n] := ... ;  # shift index by one
Alas, that doesn't quite work. If you do that you get something that looks like the following:
                           [ 11 x 2 Matrix        ]
                           [ Data Type: anything  ]
                           [ Storage: rectangular ]
                           [ Order: Fortran_order ]
The 'rtablesize' option of the interface controls the maximum size of rtables that are displayed. The default is 10. Increasing this to 11 allows this Matrix to display:
interface(rtablesize=11):
A simpler possibility, which avoids these issues is to use the printf command:
EBO := Array(0..10,1..2): # note that this is an Array, not array
...
EBO[s,n] := ...
...
printf("%0.3f\n", EBO);
1.000 4.000
0.368 3.018
0.104 2.110
0.023 1.348
0.004 0.781
0.001 0.410
0.000 0.195
0.000 0.085
0.000 0.034
0.000 0.012
0.000 0.004
I don't understand your question. What does a loop have to do with generating random data? One can use the RandomTools package to generate random values in whatever form you desire. For example,
RandomTools:-Generate(list(float(range=2..3,method=uniform), 20));
[2.277986140, 2.581869302, 2.669121262, 2.365109113, 2.545404204, 2.940029919,
    2.701693957, 2.949333985, 2.568478650, 2.249825579, 2.418932835,
    2.202810917, 2.122398916, 2.809094426, 2.201354591, 2.891235047,
    2.922939225, 2.934992634, 2.676943009, 2.969970961]
There has been some discussion on this site about efficient ways of generating random values, but at this point it isn't clear whether efficiency is even a concern.
From symmetry its clear that the solution is phi=1-2/Pi*theta, for theta from 0 to Pi. This is easily verified with the VectorCalculus package:
with(VectorCalculus):
SetCoordinates('polar[r,theta]'):
phi := 1-2/Pi*theta:
Nabla(phi);
                                    2   _
                                 - ---- e
                                   r Pi  theta
Laplacian(phi);
                                     0
Maple 11 adds the ability to readily define multiple names for a keyword parameter when assigning a procedure. That is, one can do
myproc := proc( {[capitalize,capitalise] ::= truefalse := false}) ... end proc:
to assign a procedure with a truefalse keyword parameter "capitalize" that can also be spelled "capitalise".
Here's a procedure that does what you want. Note, however, that using piecewise with a lot of conditions (100 in your case) is not very efficient. You would be better off generating a procedure that uses a binary search on the front end to select the appropriate interval.
makePW := proc(M::Matrix)
local m,n,x,r,c;
    (m,n) := op(1,M);
    unapply(piecewise(seq( [M[r,-2] < x and x <= M[r,-1], add(M[r,c]*x^(c-1), c=1..n-2)][]
                           , r = 1..m))
            , x);
end proc:
Read the ?Digits help page. The Digits environmental variable controls how many digits are used when doing software-based floating-point computation.
1.0000000005 - 1 ;
                                     0.
Digits := 20;
                                     20
1.0000000005 - 1 ;
                                       -10
                                   5 10   
Specify the range to fsolve to restrict the solution to positive values. For example,
y := -x^3-2*x^2+3*x+5;
fsolve(y, x = 0 .. infinity);
                                 1.651093409
fsolve(y, x = -infinity .. 0);
                         -2.377202854, -1.273890555
Note that with the D operator the conditional in unnecessary, that is, (D@@0)(f)(x) = f(x). However, I find the following clearer
n2 := proc(l::nonnegint)
local z,f;
    if l=0 then
        f := -cos(z)/z;
    else
        f := -(-1)^l*diff(cos(z)/z,z$l);
    end if;
    unapply(f,z);
end proc:
Occasionally I've wished that diff were extended so that diff(f,x,n), with n a nonnegint, was equivalent to diff(f,x$n), and diff(f,x,0) returned f. Then the conditional could be removed and we'd have
n2 := proc(l::nonnegint)
local z;
    unapply(-(-1)^l*diff(cos(z)/z,z,l), z);
end proc:
which is concise and clear.
Use evalf to numerically evaluate the integral:
evalf(iL_waveform_func_RMS_AVG(Ue_input,Ua_input,Ia_input,L_input,T_input,3,RMS));
                                         31.25185185
When you specify the avoid option, you should also specify a start option, so that the search doesn't get trapped. See the comments on 'avoid' in the Optional Arguments subsection of ?dsolve,details. In this case,
fsolve('Y1'(t)=Yeq, t=1, avoid={t=T1});

                                0.5225499740
Here's one approach
> y := (a/b)^(3/2)*(c*d*e/f*g*h)/(i/j)^(3/2)*(k*l*m/n*o*p);
                                   3/2
                            4 (a/b)    d e g h k l m o p
                       y := ----------------------------
                                           3/2
                                    f (i/j)    n

> vars := indets(y,name) minus {a,b,i,j};
                   vars := {e, f, p, d, k, n, g, l, m, o, h}

> fy := unapply(y, sort(convert(vars,list)));
                                                      3/2
                                               4 (a/b)    d e g h k l m o p
    fy := (d, e, f, g, h, k, l, m, n, o, p) -> ----------------------------
                                                              3/2
                                                       f (i/j)    n

> data := LinearAlgebra:-RandomMatrix(11,11,generator=0..1.0):
> for col to 11 do fy(convert(data[1..-1,col],list)[]) end do;

                                               3/2
                            0.02545310970 (a/b)
                            ----------------------
                                        3/2
                                   (i/j)
...
Naturally you wouldn't use a random Matrix. Also, I assume you'll preassign the parameters a, b, i, and j. By the way, you probably don't want to use `I' as a variable. Maple uses it as the complex unit. While you can use D, it is assigned the differential operator and protected. That isn't a problem here, since you don't have to directly assign to it, but its probably best to avoid it; that's why I used lower case for the variable names.
First 105 106 107 108 109 110 111 Page 107 of 114