acer

32328 Reputation

29 Badges

19 years, 318 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You could pass solve the option real along with the option parametric, rather than take those separate solving steps.

You could contrast the effect of then solving for [Q,XC1] versus [XC1,Q]. Note which gets expressed in some inequalities in the solution.

I removed the assignment to Q, and made that unassigned name part of the equation.

Download pi-filter_copy2_ac.mw This worksheet doens't inline well on this site.

If you do prefer performing the extra manual steps (ie. first solving explicitly for XC1, then solving in terms of Q and R1 for the radical arguments to be positive, for each intermediate solution) then it is more robust to pick off the radicals using indets rather than the problem-dependent approach of picking of subexpressions by position.

Is this the kind of thing you want?

restart

q := h*(A11*(diff(u(x, y, z, t), x, x)-(diff(w(x, y, z, t), x))/R+(diff(w(x, y, z, t), x))*(diff(w(x, y, z, t), x, x)))+A12*(diff(v(x, y, z, t), x, y)-(diff(w(x, y, z, t), x))/a+(diff(w(x, y, z, t), y))*(diff(w(x, y, z, t), x, y))))+h^2*(-B11*(diff(w(x, y, z, t), x, x, x))+B12*(-(diff(w(x, y, z, t), x, y, y))-(diff(v(x, y, z, t), x, y))/a))+B66*h^2*(-2*(diff(w(x, y, z, t), x, y, y))-(diff(v(x, y, z, t), x, y))/a)+A66*h*(diff(u(x, y, z, t), y, y)+diff(v(x, y, z, t), x, y)+(diff(w(x, y, z, t), y, y))*(diff(w(x, y, z, t), x))+(diff(w(x, y, z, t), y))*(diff(w(x, y, z, t), x, y))) = rho*(diff(u(x, y, z, t), t, t))-e0^2*a^2*(rho*(diff(u(x, y, z, t), t, t, x, x))+rho*(diff(u(x, y, z, t), t, t, y, y)))

remove(has, expand(lhs(q)), [v(x, y, z, t), w(x, y, z, t)]); L11 := collect(%, diff, simplify)

h*A11*(diff(diff(u(x, y, z, t), x), x))+A66*h*(diff(diff(u(x, y, z, t), y), y))

remove(has, expand(lhs(q)), [u(x, y, z, t), v(x, y, z, t)]); L12 := collect(%, diff, simplify)

-h^2*B11*(diff(diff(diff(w(x, y, z, t), x), x), x))-h^2*(B12+2*B66)*(diff(diff(diff(w(x, y, z, t), x), y), y))+h*A11*(diff(w(x, y, z, t), x))*(diff(diff(w(x, y, z, t), x), x))+h*(A12+A66)*(diff(w(x, y, z, t), y))*(diff(diff(w(x, y, z, t), x), y))+A66*h*(diff(diff(w(x, y, z, t), y), y))*(diff(w(x, y, z, t), x))-h*(A11*a+A12*R)*(diff(w(x, y, z, t), x))/(R*a)

remove(has, expand(lhs(q)), [u(x, y, z, t), w(x, y, z, t)]); L13 := collect(%, diff, simplify)

((A12+A66)*a-h*(B12+B66))*h*(diff(diff(v(x, y, z, t), x), y))/a

And the following happens, for this example...

simplify(expand(lhs(q))-L11-L12-L13)

0

 

Download sort_ac.mw

When you write xy without any multiplication symbol (or even a space in 2D input mode) then it just means the single name xy and has nothing to do with either name x or name y.

Also, for correctness and clarity use y(x) instead of just y, in a consistent manner.

TEST_CODE_1_ac.mw

Check your results for any remaining issues, naturally. [edit] Ask your followup queries in this same Question thread, please. (I expect you might have some... for this apparent coursework example)

 

restart;

delta := t -> piecewise(t=0, 1, 0);

delta := proc (t) options operator, arrow; piecewise(t = 0, 1, 0) end proc

plot(delta(t), t=-1..1, discont=[showremovable=true],
     color=red, thickness=4,
     symbol=solidcircle, symbolsize=20, size=[500,250]);

 

Download plot_removable.mw

You could compare the various different formulations below.

It's not clear which you might find best. You might even prefer to not supply the inequalities within the first argument passed to solve. Checking correctness all round might also be prudent.

restart

kernelopts(version)

`Maple 2019.2, X86 64 LINUX, Oct 30 2019, Build ID 1430966`

interface(showassumed = 0)

eq3 := R1*(4*Q^2+1)-RL > 0

0 < R1*(4*Q^2+1)-RL

eq4 := 4*Q^2*R1*RL-(R1-RL)^2 >= 0

0 <= 4*Q^2*R1*RL-(R1-RL)^2

eq5 := Rs^2*(RL-R1)/Q^2+R1^2*RL > 0

0 < Rs^2*(RL-R1)/Q^2+R1^2*RL

sys1 := {eq3, eq4, eq5}

This variant contains only three branches, which is interesting.
note: don't reexecute this line after applyting the additionally clauses below.
`assuming`([simplify(solve(sys1, {Q}, parametric))], [Rs::real, R1 > 0, R2 > 0, RL > 0, R1 > RL])

piecewise(Rs = 0, [[Q <= -(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2))], [(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2)) <= Q]], Or(Rs <= -(1/2)*R1^(1/2)*(R1-RL)^(1/2), (1/2)*R1^(1/2)*(R1-RL)^(1/2) <= Rs), [[Q < -(R1-RL)^(1/2)*abs(Rs)/(R1*RL^(1/2))], [(R1-RL)^(1/2)*abs(Rs)/(R1*RL^(1/2)) < Q]], Or(And(0 < Rs, Rs < (1/2)*R1^(1/2)*(R1-RL)^(1/2)), And(-(1/2)*R1^(1/2)*(R1-RL)^(1/2) < Rs, Rs < 0)), [[Q <= -(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2))], [(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2)) <= Q]], [])

This invocation (without the assuming, contains the restrictions on R1,RL in the
conditions of the output. You may prefer not to see that. Hence providing the
assumptions may serve you some purpose (even if only under the simplify step).
note: don't reexecute this after applying the additionally calls further on.

`assuming`([simplify(solve(`union`(sys1, {R1 > 0, R1 > RL, R2 > 0, RL > 0}), {Q}, parametric))], [Rs::real])

piecewise(And(0 < RL, RL < R1, Rs = 0, 0 < R2), [[Q <= -(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2))], [(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2)) <= Q]], Or(And(0 < RL, RL < R1, Rs = -(1/2)*(R1*(R1-RL))^(1/2), 0 < R2), And(0 < RL, RL < R1, Rs = (1/2)*(R1*(R1-RL))^(1/2), 0 < R2)), [[Q < -(1/2)*(R1*RL*(R1-RL)^2)^(1/2)/(R1*RL)], [(1/2)*(R1*RL*(R1-RL)^2)^(1/2)/(R1*RL) < Q]], Or(And(0 < RL, RL < R1, Rs < -(1/2)*(R1*(R1-RL))^(1/2), 0 < R2), And(0 < RL, RL < R1, (1/2)*(R1*(R1-RL))^(1/2) < Rs, 0 < R2)), [[Q < -(R1^2*RL*(R1-RL))^(1/2)*abs(Rs)/(R1^2*RL)], [(R1^2*RL*(R1-RL))^(1/2)*abs(Rs)/(R1^2*RL) < Q]], Or(And(0 < RL, RL < R1, 0 < Rs, Rs < (1/2)*(R1*(R1-RL))^(1/2), 0 < R2), And(0 < RL, RL < R1, -(1/2)*(R1*(R1-RL))^(1/2) < Rs, Rs < 0, 0 < R2)), [[Q <= -(1/2)*(R1*RL*(R1-RL)^2)^(1/2)/(R1*RL)], [(1/2)*(R1*RL*(R1-RL)^2)^(1/2)/(R1*RL) <= Q]], [])

additionally(R1, real, R2, real, RL, real, XC1, real, XC2, real, XL1, real)

additionally(R1 > 0, R2 > 0, RL > 0, XC1 > 0, XC2 > 0, XL1 > 0)

`assuming`([simplify(solve(sys1, {Q}, parametric))], [R1 > RL])

piecewise(Rs = 0, [[Q <= -(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2))], [(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2)) <= Q]], Or(Rs = -(1/2)*(R1-RL)^(1/2)*R1^(1/2), Rs = (1/2)*(R1-RL)^(1/2)*R1^(1/2)), [[Q < -(1/2)*(R1-RL)*(R1*RL)^(1/2)/(R1*RL)], [(1/2)*(R1-RL)*(R1*RL)^(1/2)/(R1*RL) < Q]], Or(Rs < -(1/2)*(R1-RL)^(1/2)*R1^(1/2), (1/2)*(R1-RL)^(1/2)*R1^(1/2) < Rs), [[Q < -(R1-RL)^(1/2)*(Rs^2*RL)^(1/2)/(RL*R1)], [(R1-RL)^(1/2)*(Rs^2*RL)^(1/2)/(RL*R1) < Q]], Or(And(0 < Rs, Rs < (1/2)*(R1-RL)^(1/2)*R1^(1/2)), And(-(1/2)*(R1-RL)^(1/2)*R1^(1/2) < Rs, Rs < 0)), [[Q <= -(1/2)*(R1-RL)*(R1*RL)^(1/2)/(R1*RL)], [(1/2)*(R1-RL)*(R1*RL)^(1/2)/(R1*RL) <= Q]], [])

`assuming`([simplify(solve(sys1, {Q}, parametric))], [Rs::real, R1 > RL])

piecewise(Rs = 0, [[Q <= -(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2))], [(1/2)*(R1-RL)/(R1^(1/2)*RL^(1/2)) <= Q]], Or(Rs = -(1/2)*(R1-RL)^(1/2)*R1^(1/2), Rs = (1/2)*(R1-RL)^(1/2)*R1^(1/2)), [[Q < -(1/2)*(R1-RL)*(R1*RL)^(1/2)/(R1*RL)], [(1/2)*(R1-RL)*(R1*RL)^(1/2)/(R1*RL) < Q]], Or(Rs < -(1/2)*(R1-RL)^(1/2)*R1^(1/2), (1/2)*(R1-RL)^(1/2)*R1^(1/2) < Rs), [[Q < -(R1-RL)^(1/2)*abs(Rs)/(RL^(1/2)*R1)], [(R1-RL)^(1/2)*abs(Rs)/(RL^(1/2)*R1) < Q]], Or(And(0 < Rs, Rs < (1/2)*(R1-RL)^(1/2)*R1^(1/2)), And(-(1/2)*(R1-RL)^(1/2)*R1^(1/2) < Rs, Rs < 0)), [[Q <= -(1/2)*(R1-RL)*(R1*RL)^(1/2)/(R1*RL)], [(1/2)*(R1-RL)*(R1*RL)^(1/2)/(R1*RL) <= Q]], [])

 

Download pi-filter_copy_ac.mw

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

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