acer

32385 Reputation

29 Badges

19 years, 336 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

As mentioned, the with command won't work within a procedure. But orthopoly isn't needed here anyway.

You should not unprotect gamma. But you don't need to touch the global name gamma anyway (as you can use it as a procedure parameter or even a local).

You should not unprotect Psi. Instead you can declare a top-level local of the same name, in your Maple 2020.

The operators that your code constructs inside functionA and functionB contain references to the global K. Yet functionA and functionB bother to set up their local K (using passed k). This is a muddle. By using the unapply command your functionA and functionB can construct the operators with the precomputed K value. Then you don't need to recompute K at the level from which you call functionA and functionB in examples.

There were a few other problematic situations possible with the other variables in the formulas, due to not utilizing unapply.

Your functionA and functionB were using the global name x without protection against it being assigned. [edit] The same goes for n and m. So all three can be better declared as locals of functionA and functionB.

Your formulas used to construct the w operator don't depend upon n, so I removed that parameter from its construction.

Your example code used many full colons, supressing output and hiding some of the issues.

You don't need to save/load this module to a .mla Library archive, just to test its basics.

You should stress-test this revision.

restart;

test:=module()
  export functionA,functionB;
  option package;
  functionA:=proc(k,M) local K,n,m,x;
    K:=2^(k-1);
    unapply(piecewise((n-1)/K <= x and x <= n/K,
                      (sqrt((m+1/2)*2^k))*LegendreP(m,2^k*x-2*n+1),
                      0),
            [n,m,x]),
    (x)->1;
  end proc:

  functionB:=proc(k,M,epsilon,gamma) local K,h,n,m,x;
    K:=2^(k-1):
    h:=simplify(2^(epsilon+gamma+1)*GAMMA(epsilon+m+1)
                *GAMMA(gamma+m+1)/((2*m+1+epsilon+gamma)
                                   *m!*GAMMA(epsilon+gamma+1)))
         assuming n::posint, m::posint;
    unapply(piecewise((n-1)/K <= x and x <= n/K,
                      'simplify'(2^(k/2)*h
                                 *JacobiP(m,epsilon,gamma,2^(k)*x-2*n+1)),
                      0),
            [n,m,x]),
    unapply((1-x)^(epsilon)*(1+x)^gamma, [x]);
end proc:

end module:

with(test);

[functionA, functionB]

# For k=2,M=3 in FunctionA, let's calculate values
# of "Psi(4/10)" and "w(x)"

(psi,w):=functionA(2,3);
local Psi:=x->Array([seq(seq(psi(i,j,x),j=0..3-1),i=1..2^(2-1))] )^+:
Psi(4/10);
w(x);

psi, w := proc (n, m, x) options operator, arrow; piecewise((1/2)*n-1/2 <= x and x <= (1/2)*n, sqrt(4*m+2)*LegendreP(m, 4*x-2*n+1), 0) end proc, proc (x) options operator, arrow; 1 end proc

Vector[column](%id = 18446883720063049726)

1

# Now, let's calculate values of "Psi(4/10)" and "w(x)"
# for k=3,M=4, epsilon=1, gamma=2 in FunctionB

(psi,w):=functionB(3,4,1,2);
local Psi:=x->Array([seq(seq(psi(i,j,x),j=0..3-1),i=1..2^(2-1))] )^+:
Psi(4/10);
w(x);

psi, w := proc (n, m, x) options operator, arrow; piecewise((1/4)*n-1/4 <= x and x <= (1/4)*n, simplify((8/3)*sqrt(2)*(m+1)*GAMMA(m+2)*JacobiP(m, 1, 2, 8*x-2*n+1)), 0) end proc, proc (x) options operator, arrow; (1-x)*(x+1)^2 end proc

Vector[column](%id = 18446883720063038638)

(1-x)*(x+1)^2

 

Download ML_code_ac.mw

The global name gamma has a special meaning in Maple, and refers to a particular real constant. (That's why you cannot assign a new value to it. The name is protected.)

The error message from the implicitplot command is due to your use of the global name of the constant gamma on the left hand side of R.

The simplest course of action in your Maple 11 is to use another name instead.

For your first question, it seems to me you are asking about the functionality provided by the unapply command.

And for your second question, a DataFrame might possibly serve.

See a link to the attachment below.

restart;

u := <-0.0223, 0.00593, -0.0257, 0.143, 0.082, 0.986>;

Vector(6, {(1) = -0.223e-1, (2) = 0.593e-2, (3) = -0.257e-1, (4) = .143, (5) = 0.82e-1, (6) = .986})

fonction := unapply(u(1)*x^2+u(2)*x*y+u(3)*y^2
                    +u(4)*x+u(5)*y+u(6), [x,y]);

proc (x, y) options operator, arrow; -0.223e-1*x^2+0.593e-2*y*x-0.257e-1*y^2+.143*x+0.82e-1*y+.986 end proc

A := evalf[4](LinearAlgebra:-RandomMatrix(5,6,generator=-100.0..100.0));

Matrix(5, 6, {(1, 1) = -65.76, (1, 2) = 35.75, (1, 3) = 91.90, (1, 4) = 60.06, (1, 5) = 92.98, (1, 6) = 26.47, (2, 1) = 31.10, (2, 2) = 86.80, (2, 3) = 58.44, (2, 4) = -2.925, (2, 5) = 91.50, (2, 6) = 82.68, (3, 1) = -21.55, (3, 2) = 69.83, (3, 3) = 83.15, (3, 4) = 91.43, (3, 5) = 9.376, (3, 6) = -74.60, (4, 1) = 48.63, (4, 2) = -92.86, (4, 3) = -15.65, (4, 4) = 94.12, (4, 5) = -44.30, (4, 6) = 81.16, (5, 1) = 51.55, (5, 2) = 31.15, (5, 3) = -71.62, (5, 4) = -68.48, (5, 5) = -80.49, (5, 6) = 62.94})

DF := DataFrame(A, 'columns'=[$1..6]);

DataFrame(Matrix(5, 6, {(1, 1) = -65.76, (1, 2) = 35.75, (1, 3) = 91.90, (1, 4) = 60.06, (1, 5) = 92.98, (1, 6) = 26.47, (2, 1) = 31.10, (2, 2) = 86.80, (2, 3) = 58.44, (2, 4) = -2.925, (2, 5) = 91.50, (2, 6) = 82.68, (3, 1) = -21.55, (3, 2) = 69.83, (3, 3) = 83.15, (3, 4) = 91.43, (3, 5) = 9.376, (3, 6) = -74.60, (4, 1) = 48.63, (4, 2) = -92.86, (4, 3) = -15.65, (4, 4) = 94.12, (4, 5) = -44.30, (4, 6) = 81.16, (5, 1) = 51.55, (5, 2) = 31.15, (5, 3) = -71.62, (5, 4) = -68.48, (5, 5) = -80.49, (5, 6) = 62.94}), rows = [1, 2, 3, 4, 5], columns = [1, 2, 3, 4, 5, 6])

Tabulate(DF, widthmode=pixels, width=550):

 

 

1

2

3

4

5

6

1

-65.76

35.75

91.90

60.06

92.98

26.47

2

31.10

86.80

58.44

-2.925

91.50

82.68

3

-21.55

69.83

83.15

91.43

9.376

-74.60

4

48.63

-92.86

-15.65

94.12

-44.30

81.16

5

51.55

31.15

-71.62

-68.48

-80.49

62.94

 

 

 

DF[1];

DataSeries(Vector[row](5, {(1) = -65.76, (2) = 31.10, (3) = -21.55, (4) = 48.63, (5) = 51.55}), labels = [1, 2, 3, 4, 5], datatype = anything)

DF[1,1], DF[3,4], DF[5,2];

-65.76, 91.43, 31.15

 

unapply_df.mw

The first step can be done using the rationalize command.

The second step can be done by rewriting the given substitution equation.

restart;

Io := I*Cp*Vin*L1/(M*sqrt(Cp*L1));

I*Cp*Vin*L1/(M*(Cp*L1)^(1/2))

ans1 := rationalize(Io);

I*(Cp*L1)^(1/2)*Vin/M

S1 := w = 1/sqrt(L1*Cp);
S2 := (1/rhs=1/lhs)(S1);

w = 1/(Cp*L1)^(1/2)

(Cp*L1)^(1/2) = 1/w

ans2 := subs(S2, ans1);

I*Vin/(w*M)

``

Download Resonant_xformer_ac.mw

Here's another variant, using InertForm with the inert operators for the divisions and additions, and with the active operator for multiplications. The active multiplications are implicitly displayed in output (ie. the multiplication symbol suppressed).

Download SérieAléaEqFractionnaires1_ac.mw

Your document had the same operations done multiple times. You don't have to load the InertForm package (utilizing the with command). You certainly don't have to call with multiple times.

You could turn the example generator into a procedure, to make it all cleaner.

You could also use Embedded Components, with each new example replaing the old one. (It could be as simple, or as fancy, as you choose.)

Your document also made me think of the Quiz package.

evalc(sqrt(-x^2-y^2));

I*(x^2+y^2)^(1/2)

Download sqrt_evalc.mw

How do you feel about t=0 ?

The odeplot command makes it easy to specify what goes on which axis.

restart;

ode := diff(x(t), t) = 16250.25391*(1 - (487*x(t))/168 + 4*Pi*x(t)^(3/2) + (274229*x(t)^2)/72576 - (254*Pi*x(t)^(5/2))/21 + (119.6109573 - (856*ln(16*x(t)))/105)*x(t)^3 + (30295*Pi*x(t)^(7/2))/1728 + (7.617741607 - 23.53000000*ln(x(t)))*x(t)^4 + (535.2001594 - 102.446*ln(x(t)))*x(t)^(9/2) + (413.8828821 + 323.5521650*ln(x(t)))*x(t)^5 + (1533.899179 - 390.2690000*ln(x(t)))*x(t)^(11/2) + (2082.250556 + 423.6762500*ln(x(t)) + 33.2307*ln(x(t)^2))*x(t)^6)*x(t)^5:

ics := x(0) = xlow:

sol := dsolve({ics, ode}, numeric, parameters=[xlow], method=rosenbrock):
sol(parameters=[xlow=8e-2]):

sol(1);

Error, (in sol) cannot evaluate the solution further right of .30133640, probably a singularity

sol(last);
tmax := eval(t,%);

[t = HFloat(0.3013364074642204), x(t) = HFloat(2.3363766640055337)]

HFloat(0.3013364074642204)

plots:-odeplot(sol, [[t,x(t)],[x(t),t]], 0 .. tmax,
               color=[red,blue], view=[0..0.5,0..0.5]);

plots:-odeplot(sol, [x(t),t], 0 .. tmax,
               color=[blue], view=[0..0.5,0..0.5]);

 

Download odeplot_v.mw

A small modification of your code gets you the following. Is it something like your goal?

You could easily make it a procedure.

restart;

with(LinearAlgebra):

A := Matrix([[2, 3, -4], [0, -4, 2], [1, -1, 5]]);

Matrix(3, 3, {(1, 1) = 2, (1, 2) = 3, (1, 3) = -4, (2, 1) = 0, (2, 2) = -4, (2, 3) = 2, (3, 1) = 1, (3, 2) = -1, (3, 3) = 5})

Ad := Matrix(3,3):
for i to 3 do for j to 3 do
  Ad[j,i] := (-1)^(i+j)*Minor(A, i, j);
end do end do:
Ad;

Matrix(3, 3, {(1, 1) = -18, (1, 2) = -11, (1, 3) = -10, (2, 1) = 2, (2, 2) = 14, (2, 3) = -4, (3, 1) = 4, (3, 2) = 5, (3, 3) = -8})

Adjoint(A);

Matrix(3, 3, {(1, 1) = -18, (1, 2) = -11, (1, 3) = -10, (2, 1) = 2, (2, 2) = 14, (2, 3) = -4, (3, 1) = 4, (3, 2) = 5, (3, 3) = -8})

Download adjoint.mw

restart;

ee := cos( sqrt(Lr1+Lr2)*t/(sqrt(Cr)*sqrt(Lr1)*sqrt(Lr2)));

cos((Lr1+Lr2)^(1/2)*t/(Cr^(1/2)*Lr1^(1/2)*Lr2^(1/2)))

combine(ee,radical,symbolic);

cos(t*((Lr1+Lr2)/(Cr*Lr1*Lr2))^(1/2))

combine(ee) assuming Lr1<0, Lr2<0, Cr<0:
normal(%);

cos(t*((Lr1+Lr2)/(Cr*Lr1*Lr2))^(1/2))

combine(ee) assuming Lr1>0, Lr2>0, Cr>0;

cos(t*((Lr1+Lr2)/(Cr*Lr1*Lr2))^(1/2))

 

Download rad_combine.mw

I have not utilized the cosine property cos(-z)=cos(z) however.

You can represent this operation with a call to %.  as an inert noncommutative multiplicaion.

The dot symbol renders in gray by default, but you can also use InertForm:-Display to render it in black.

The value command is one mechanism (of several) that turns it into an active computation.

restart;

A:=Matrix([[1,2,3],[4,5,6],[7,8,9]]):
b:=Vector([1,2,3]):
X:=Vector([x,y,z]):

eq := A %. X = b:

eq;

`%.`(Matrix(3, 3, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 3, (2, 1) = 4, (2, 2) = 5, (2, 3) = 6, (3, 1) = 7, (3, 2) = 8, (3, 3) = 9}), Vector(3, {(1) = x, (2) = y, (3) = z})) = (Vector(3, {(1) = 1, (2) = 2, (3) = 3}))

InertForm:-Display(eq, inert=false);

`?` = (Vector(3, {(1) = 1, (2) = 2, (3) = 3}))

value(eq);

(Vector(3, {(1) = x+2*y+3*z, (2) = 4*x+5*y+6*z, (3) = 7*x+8*y+9*z})) = (Vector(3, {(1) = 1, (2) = 2, (3) = 3}))

Download inertmatmul.mw

[edit] Changed to an infix call, see comments below.

simplify(eval([y,z],aa[1])-eval([y,z],bb[2]))
   assuming alpha[1,8]>0;

                [0, 0]

radnormal(eval([y,z],aa[1])-eval([y,z],bb[2]))
   assuming alpha[1,8]>0;

                [0, 0]

I do not recommend in general your original approach of comparing a pair of simplify results using evalb, ie. testing whether they are the identical same structure. In general there may not be a definitive normal form, and so it is an unnecessarily weakened test -- despite the fact that it succeeds in this example involving radicals.

Under the assumption used above,

# I don't much like this first one, even if
# it works for your polynomial solutions.
evalb(simplify(aa[1,1])=simplify(bb[2,1]))
   assuming alpha[1,8]>0;

                true

# I'd prefer a check more like this.
is(simplify(aa[1,1]-bb[2,1]))
   assuming alpha[1,8]>0;

                true

# Alternatively,
is(simplify(eval(y,aa[1])-eval(y,bb[2]))=0)
   assuming alpha[1,8]>0;

                true

You didn't state what you wanted the titles to be.

restart;

dim:=3:
flat:=(j - 1 + dim*(i - 1))+1;

pltopts:=color=blue,size=[250,250],tickmarks=[0,0]:
s:=[seq(
    [seq(plot(diff(x^9,[x$(flat)]),pltopts,
              title=typeset(InertForm:-Display(%diff(x^9,[x$(flat)]),
                                               inert=false)
                            = diff(x^9,[x$(flat)])),
              titlefont=["Times",10]
       )
    ,j=1..dim)],
i=1..dim)]:
A:=Array(1..dim,1..dim,s):

j+3*i-3

plots:-display(A)

 

 

 

 

 

``

Download QuestionTabulation_ac.mw

Put both in one more call to plots:-display.

You have mistmatched brackets in the expression assigned to wres.

You forgot the colon in the colon-minus ( := ) in the line that seems to define z3. As you have it, that line is just an equation, rather than as assignment.

You used lowercase pi when perhaps you intended the popular constant Pi which is capitalized in Maple.

First 103 104 105 106 107 108 109 Last Page 105 of 336