acer

32405 Reputation

29 Badges

19 years, 351 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The op command can extract the operands of a radical.

In particular, you can use op(1, ee)  where ee evaluates to the radical. And you can map that across a set or a list of radicals.

You can extract all subexpressions of type radical from an expression using the indets command. That returns them as a set.

For example,

expr := sin(sqrt(b^2-4*a*c)) + sqrt(bar):

map[2](op,1,indets(expr,radical));

                            2
            {bar, -4 a c + b }

# Alternatively, applying the op command elementwise
# over the set.
op~(1,indets(expr,radical));

                            2
            {bar, -4 a c + b }

You can subsequently create new expressions from those operands, such as inequalities, etc.

I'm not sure that I understand what you ask about a "Matrix".

But ColorTools:-Gradient can produce a list across a range of colors in a colorspace. (It includes the endpoints, so number can be supplied as two less than the target.)

Your can choose between various color spaces. You can experiment, if say you wish to avoid a gray area, etc. The "Luv" color space may provide a result where a linear transition is more visually even than that from the "RGB" default. (RGB is more even in terms of what your monitor emits, but Luv and Lab may be more even in terms of what the average eye perceives.)

note. The various Gradient results at the botton look different in the actual Maple GUI than they do inlined here.

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

N := 10;

10

MyColors := ColorTools:-Gradient("Gold".."Blue", 'number'=N-2, 'space'="Luv"):

M := numelems(MyColors);

10

plots:-display(

  seq(

    plot(m*x^2, x=0..1, color=MyColors[m]),

    m=1..N

  )

);

ColorTools:-Gradient("Gold".."Blue", 'number'=N-2 );

[_m139933477742400, _m139933477742784, _m139933477743200, _m139933477743616, _m139933477744032, _m139933477744448, _m139933477736672, _m139933477737088, _m139933477737504, _m139933477737920]

ColorTools:-Gradient("Gold".."Blue", 'number'=N-2, 'space'="RGB" );

[_m139933477287264, _m139933477287648, _m139933477288064, _m139933477288480, _m139933477288896, _m139933477289312, _m139933477289728, _m139933477068960, _m139933477069376, _m139933477069792]

ColorTools:-Gradient("Gold".."Blue", 'number'=N-2, 'space'="Luv" );

[_m139933476690208, _m139933476690912, _m139933476691680, _m139933476684256, _m139933476685056, _m139933476685824, _m139933476686592, _m139933476687360, _m139933476679904, _m139933476680672]

ColorTools:-Gradient("Gold".."Blue", 'number'=N-2, 'space'="Lab" );

[_m139933475311424, _m139933475303872, _m139933475304576, _m139933475305280, _m139933475306016, _m139933475306720, _m139933475307456, _m139933475300000, _m139933475300736, _m139933475301504]

ColorTools:-Gradient("Gold".."Blue", 'number'=N-2, 'space'="HSV" );

[_m139933474124704, _m139933474125376, _m139933474126080, _m139933474126784, _m139933474127488, _m139933474120000, _m139933474120704, _m139933474121376, _m139933474122048, _m139933474122784]

 

Download colorgradient.mw

Conditionals are tested (under if..then, as a Boolean) using evalb as the basic mechanism. That Help page for evalb states,

    An evalb call using <, <=, >, or >= returns evaluated only with arguments
    of type extended_numeric, complex, or string.

That Help page also contains an example involving an exact radical, where it uses the is and the evalf commands instead.

if is(2+89^(1/2)>0) then
   print("yes");
else
   print("no");
end if;

              "yes"

The eval command provides the functionality to evaluate an expression using the equations.

You can also use it to evaluate one or more names (on the LHS of those equations) to pick off the values. (This is also more robust when the equations are in sets, as it doesn't depend on their ordinal poisition.)

Sometimes this use of eval is call 2-argument eval.

I also show how you can utilize eval in this manner, without having to assign the names to new temp variables. You can of course experiment.

Check the results, as I'm not sure what roles all the names take throughout. I may have used it in a way other than you intended.

new_filter_solution_1_ac.mw

note. To express, say, 2*10.0^(-12) you could type in 2e-12 without space before the e.

note. You have large and small numeric quantities around. You might wish to use a higher working precision to guard against roundoff error. That can be done using evalf[N] or higher Digits. I'm not sure it is needed, though.

 

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.

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