sursumCorda

1002 Reputation

13 Badges

1 years, 231 days

MaplePrimes Activity


These are answers submitted by sursumCorda

Use op(⑴) or ⑴[]

isolate([6600.0*theta(q) - 17000.0*theta(q - 1) + 14400.0*theta(q - 2) - 4000.0*theta(q - 3) = v(q) - 0.20*theta(q) + 0.20*theta(q - 1)][], theta(q));
 = 
 theta(q) = 2.575709827 theta(q - 1) - 2.181752068 theta(q - 2)

    + 0.6060422412 theta(q - 3) + 0.0001515105603 v(q)


 

One may use the forgotten applyrule
 

transformed impulse response (

(10*exp(3/10)-7*exp(1/5)-3*exp(2/5))*exp(1/10)*U(z)/z+(exp(1/10)*(-3+10*exp(1/10)-7*exp(1/5))-(10*exp(3/10)-7*exp(1/5)-3*exp(2/5))*exp(1/10))*U(z)/z^2-(-3+10*exp(1/10)-7*exp(1/5))*exp(1/10)*U(z)/z^3 = 8*Y(z)*exp(1/10)*exp(3/10)*exp(1/5)+(8*((-exp(1/5)-exp(3/10))*exp(1/10)-exp(3/10)*exp(1/5)))*Y(z)/z+(8*(exp(1/10)+exp(1/5)+exp(3/10)))*Y(z)/z^2-8*Y(z)/z^3

(10*exp(3/10)-7*exp(1/5)-3*exp(2/5))*exp(1/10)*U(z)/z+(exp(1/10)*(-3+10*exp(1/10)-7*exp(1/5))-(10*exp(3/10)-7*exp(1/5)-3*exp(2/5))*exp(1/10))*U(z)/z^2-(-3+10*exp(1/10)-7*exp(1/5))*exp(1/10)*U(z)/z^3 = 8*Y(z)*exp(1/10)*exp(3/10)*exp(1/5)+8*((-exp(1/5)-exp(3/10))*exp(1/10)-exp(3/10)*exp(1/5))*Y(z)/z+8*(exp(1/10)+exp(1/5)+exp(3/10))*Y(z)/z^2-8*Y(z)/z^3

(1)

deg_mx := 3

3

(2)

Replacements to get finite difference equation

[seq(U(z)/z^i = U[q+1-i], i = deg_mx .. 0, -1), seq(Y(z)/z^i = Y[q+1-i], i = deg_mx .. 0, -1)]

[U(z)/z^3 = U[q-2], U(z)/z^2 = U[q-1], U(z)/z = U[q], U(z) = U[q+1], Y(z)/z^3 = Y[q-2], Y(z)/z^2 = Y[q-1], Y(z)/z = Y[q], Y(z) = Y[q+1]]

(3)

Attempt to replace

"map2(applyrule,,)" =

U[q]*(10*exp(3/10)-7*exp(1/5)-3*exp(2/5))*exp(1/10)+U[q-1]*(exp(1/10)*(-3+10*exp(1/10)-7*exp(1/5))-(10*exp(3/10)-7*exp(1/5)-3*exp(2/5))*exp(1/10))-U[q-2]*exp(1/10)*(-3+10*exp(1/10)-7*exp(1/5)) = 8*Y[q+1]*exp(1/10)*exp(3/10)*exp(1/5)+Y[q]*(8*(-exp(1/5)-exp(3/10))*exp(1/10)-8*exp(3/10)*exp(1/5))+Y[q-1]*(8*exp(1/10)+8*exp(1/5)+8*exp(3/10))-8*Y[q-2]

(4)

%?


 

Download Another_way.mws

By the way, the new command Physics:-Substitute is too "smart" here.

Maple's rational conversion function is `convert/rational`.

Two examples: 
 

 

 

restart

M__1 := `<|>`(`<,>`(1, 5, 9, 13), `<,>`(2, 6, 10, 14), `<,>`(3, 7, 11, 15), `<,>`(4, 8, 12, 16))

Matrix(%id = 36893490308353225180)

(1.1)

M__2 := (Vector[row](4, {(1) = 17, (2) = 18, (3) = 19, (4) = 20}))^%T

Vector[column](%id = 36893490308353213252)

(1.2)

zip[inplace](`/`@@2, M__1, `<|>`(`$`(M__2, 4)))

Matrix(%id = 36893490308353225180)

(1.3)

M__1

Matrix(%id = 36893490308353225180)

(1.4)

 

 

restart

M__1 := `<|>`(`<,>`(1, 5, 9, 13), `<,>`(2, 6, 10, 14), `<,>`(3, 7, 11, 15), `<,>`(4, 8, 12, 16))

Matrix(%id = 36893490308353225180)

(2.1)

M__2 := (Vector[row](4, {(1) = 17, (2) = 18, (3) = 19, (4) = 20}))^%T

Vector[column](%id = 36893490308353213252)

(2.2)

M__1 := reduce(`<|>`, ArrayTools:-GeneralInnerProduct(M__2, `<,>`, `/`, M__1))

Matrix(%id = 36893490308353205060)

(2.3)

NULL


 

Download elementwise_division.mw

Edit. Note that if you don't need the inplace option, 

M1 := zip(`/`, `<|>`(M2, n), M1):

or @acer's 

M1 := `<|>`(M2$n)/~M1:

is much faster than 

zip[inplace](`/`@@2, M1, `<|>`(M2, n)):

Besides, the advantage of the second example above is that we don't need know the dimensions. (In fact, @dharr's 

M1 := LinearAlgebra:-DiagonalMatrix(M2)*M1 ^~ (-1):

 is faster, but it doesn't work in generalized cases.)

map(f, a + b, t);
 = 
                       f(a, t) + f(b, t)

I think that this is due to Maple's internal machinery of the simplification.
Compare: (Which one do you think is simpler for the subscribers? Maple's (-c - d)*b + a or Mathematica's a - b*(c + d)?)

> simplify([a - b*c - b*d, a - b*2 - c*2]); (*Maple*)
                                            [(-c - d) b + a, a - 2 b - 2 c]


In[1]:= Simplify[{a - b*c - b*d, a - b*2 - c*2}] (*another CAS*)

Out[1]= {a - b (c + d), a - 2 (b + c)}

However, I find that if we work in degrees, Degrees[Simplify] will give a more readable result: 

use Degrees in Simplify(x = -sind(alpha)*(L + (e + r)/tand(-90 + alpha/2))/2 + sind(alpha)*L) end;
 = 
    /                     /1      \                  /1      \\ 
x = |(e + r) Degrees:-sind|- alpha| + L Degrees:-cosd|- alpha|| 
    \                     \2      /                  \2      // 

               /1      \
  Degrees:-sind|- alpha|
               \2      /



The reason for the failure is: 

ToInert(op([1, 2, -1], sol)):

is not identical to 

ToInert(_Z1):

However, this works inelegantly

parse(StringTools:-Subs({"_B2" = "n", "_Z1" = "n", "_Z2" = "n"}, String(sol)));
 = 
           /                     1            2  
          { alpha = Pi n, beta = - Pi + 2 Pi n , 
           \                     2               

                           /2    /      2\\         \ 
            lambda = arctan|- sin\2 Pi n /| + Pi _Z4 }
                           \3             /         / 


 

If we work with closed intervals, another approach can be adopted. (Firstly, one must convert RealRange into list.) 

mergeThem := proc(bds::nonemptylist(And([realcons, realcons], satisfies(x -> is(x[1] <= x[2])))), $) 
    option encrypted; 
    uses ListTools; 
    local aux := map([min, max], [Categorize]((x, y) -> is(x[2] >= y[1]) and is(y[2] >= x[1]), bds)); 
    `if`(Sorted(aux[sort(evalf(aux), output = permutation)], (x, y) -> is(x[2] < y[1])), RETURN(aux), thisproc(aux)); 
    end:

Appendix. In the style of Mathematica

mergeThem@bds:{{(-Infinity|_?NumericQ|Infinity)~Repeated~{2}}?(Apply@FullSimplify@*LessEqual)..}:=NestWhile[MinMax/@OperatorApplied[Gather][VectorGreaterEqual[{{Indexed[#1,{2}],Indexed[#2,{2}]},{Indexed[#2,{1}],Indexed[#1,{1}]}}]&/*FullSimplify][#]&,bds,!OrderedQ[NumericalSort@#,#1[[2]]<#2[[1]]&//FullSimplify]&]

See also https://www.mapleprimes.com/questions/39068-Unions-Of-Ranges and https://www.mapleprimes.com/questions/230430-How-To-Perform-Set-Operations-With-Intervals.

A subtle point: You have to use [algebraic, algebraic, algebraic] rather than [algebraic $ 3]. Alternatively, 

restart;

test := proc(l1::[{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)}, 'Vector[column]'(3, algebraic)], l2::[{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)}, 'Vector[column]'(3, algebraic)]) print("inputs recognised") end;

proc (l1::[{satisfies(proc (s) options operator, arrow; type(s, [`$`(algebraic, 3)]) end proc), ('Vector[row]')(3, algebraic)}, ('Vector[column]')(3, algebraic)], l2::[{satisfies(proc (s) options operator, arrow; type(s, [`$`(algebraic, 3)]) end proc), ('Vector[row]')(3, algebraic)}, ('Vector[column]')(3, algebraic)]) print("inputs recognised") end proc

(1)

l1 := [`<|>`(1, 5, 7), `<,>`(3, 7, 9)] = [Vector[row](3, {(1) = 1, (2) = 5, (3) = 7}), Vector(3, {(1) = 3, (2) = 7, (3) = 9})]NULL

l2 := [`<|>`(-4, 2, 1), `<,>`(3, 8, -9)] = [Vector[row](3, {(1) = -4, (2) = 2, (3) = 1}), Vector(3, {(1) = 3, (2) = 8, (3) = -9})]NULL

test(l1, l2)

"inputs recognised"

(2)

l3 := [[1, 5, 7], `<,>`(3, 7, 9)] = [[1, 5, 7], Vector(3, {(1) = 3, (2) = 7, (3) = 9})]NULL

l4 := [[-4, 2, 1], `<,>`(3, 2, -9)] = [[-4, 2, 1], Vector(3, {(1) = 3, (2) = 2, (3) = -9})]NULL

test(l3, l4)

"inputs recognised"

(3)

NULL


 

Download Procedure_testing_types_in_list_inputs.mw

X:=(eval@@2)(foldl(''SubstituteAll'',s,''op''([L1[k],L2[k]])$k=1..numelems(L1)));
 = 
  X := "{ {0, 1}, {1, 2}, {1, 10}, {2, 3}, {3, 4}, {4, 5},

    {4, 9}, {5, 6}, {6, 7}, {7, 8},{8, 9}, {10, 11}, {11, 12},

    {11, 16}, {12, 13}, {13, 14}, {14, 15}, {15, 16}}"


Besides, if we don't know StringTools[CharacterMap]

Subs(convert(L1, list) =~ convert(L2, list), s); # also works
 = 
  "{ {0, 1}, {1, 2}, {1, 10}, {2, 3}, {3, 4}, {4, 5},

    {4, 9}, {5, 6}, {6, 7}, {7, 8},{8, 9}, {10, 11}, {11, 12},

    {11, 16}, {12, 13}, {13, 14}, {14, 15}, {15, 16}}"


 


 

restart;

bigList := RandomTools:-Generate(listlist(integer(range = -10^3 .. 10^3), 10^4, 10^2))

s1 := CodeTools:-Usage(subsindets(bigList, list, convert, set))

memory used=27.62MiB, alloc change=8.00MiB, cpu time=703.00ms, real time=560.00ms, gc time=281.25ms

 

s2 := CodeTools:-Usage(convert(map(convert, bigList, set, nested), set, nested))

memory used=20.30MiB, alloc change=0 bytes, cpu time=375.00ms, real time=382.00ms, gc time=0ns

 

s3 := CodeTools:-Usage(convert(convert(bigList, Array, fill = NULL), set, nested))

memory used=32.15MiB, alloc change=35.63MiB, cpu time=859.00ms, real time=788.00ms, gc time=203.12ms

 

is(s1 = s2 and s2 = s3) = trueNULL


 

Download nested_convert_to_set.mw

More or less useful: 

with(VectorCalculus):
B := piecewise(0 <= r < a, <0, mu[0]*r^3*i/(2*Pi*a^4), 0>, a <= r <= b, <0, mu[0]*i/((1 + r)*r*Pi), 0>);
 B :=  /                  3                                    
       |         &mu;[0] r  i                                  
       |  0 e  + ------------ e  + 0 e        0 <= r and r < a 
       |     x            4    y      z                        
      <           2 &pi; a                                     
       |                                                       
       |          &mu;[0] i                                    
       | 0 e  + -------------- e  + 0 e       a <= r and r <= b
       \    x   (1 + r) r &pi;  y      z                       

n := <0, 1, 0>:
PIECEWISE(map(x -> [x[2] . n, x[1]], PiecewiseTools:-ToList(B))[]);
 = 
              /         3                          
              |  mu[0] r  i                        
              |  ----------       0 <= r and r < a 
              |         4                          
             <    2 Pi a                           
              |                                    
              |   mu[0] i                          
              | ------------      a <= r and r <= b
              \ (1 + r) r Pi                       

 

Find a satisfying assignment using SMTLIB:-Satisfy

SMTLIB:-Satisfy({2*c2 + c0 = 1, 3*c2 + 12*c4 = 1, 6*c3 + 2*c1 = 2});
 = 
           /                             1       1 \ 
          { c0 = 1, c1 = 0, c2 = 0, c3 = -, c4 = -- }
           \                             3       12/ 

And you can try another solver cvc5 online (cf. SMTLIB:-ToString).

Incidentally, the algorithms used by MMA's FindInstance are described here

Much convenient: 
 

restart;

"applyrule(f(_A::anything)+f(_B::anything)=f(_A+_B),((e)^(f(a)-f(c)+2 (f(b)+f(c))+f(10*d)))/((e)^(f(b)+f(NULL)+f(``)))+((e)^(f(a)-f(c)+2*(f(b)+f(c))+f(10 d)))/((e)^(f(b)+f(NULL)+f(``)))+e/(f(f(""))+f(f(g))+f(f(h))+f^(1)(""))+e/(f(f(""))+f(f(g))+f(f(h))+f^(-1)("")))"
 =
exp(f(a+10*d)-f(c)+2*`&InvisibleTimes;`(f(b+c)))/exp(f(``+b)+f())+exp(f(10*d*`&InvisibleTimes;`+a+c)+2*f(b))/exp(f(``+b)+f())+e/f(""+f("")+f(g)+f(h))+e/(f(f(h+""+g))+(f@@(-1))(""))

redefine(f, ['multilinear'])%

exp(f(a)+10*f(d)-f(c)+2*`&InvisibleTimes;`(f(b)+f(c)))/exp(f(``)+f(b))+exp(10*f(`&InvisibleTimes;`*d)+f(a)+f(c)+2*f(b))/exp(f(``)+f(b))+e/(f(f(""))+f(f(g))+f(f(h))+f(""))+e/(f(f(""))+f(f(g))+f(f(h))+(f@@(-1))(""))

(1)

NULL


 

Download possibleMatch.mw

Maybe Physics/diff
 

p := (m1*a1 + m2*(a123 + z(t)))*sin(theta(t))*g + m3*(sin(theta(t))*(a1234 + z(t)) + cos(theta(t))*a5)*g; = (m1*a1+m2*(a123+z(t)))*sin(theta(t))*g+m3*(sin(theta(t))*(a1234+z(t))+cos(theta(t))*a5)*gNULL

diff((m1*a1+m2*(a123+z))*sin(theta)*g+m3*(sin(theta)*(a1234+z)+cos(theta)*a5)*g, theta) = (m1*a1+m2*(a123+z))*cos(theta)*g+m3*(cos(theta)*(a1234+z)-sin(theta)*a5)*g

Physics[diff](p, theta(t))

(m1*a1+m2*(a123+z(t)))*cos(theta(t))*g+m3*(cos(theta(t))*(a1234+z(t))-sin(theta(t))*a5)*g

(1)

NULL


 

Download Fundiff.mw

1 2 3 4 5 Page 4 of 5