acer

32303 Reputation

29 Badges

19 years, 309 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

As a tip for future queries,

> MmaTranslator:-FromMma("Hypergeometric0F1Regularized[a, z]");

        hypergeom([], [a], z)
        ---------------------
              GAMMA(a)

> lprint(%);

hypergeom([],[a],z)/GAMMA(a)

You have used Maple 2021, and 2D Input.

In that case you can use the prefix form of the inert `%.` operator.

Also, to get it to display in infix notation as output, you'd need to utilize the extended typesetting level. (In that case the "dot" appears in gray.)

You can use InertForm:-Display to show the "dot" in black, instead of gray.

And you can use the value command to make the inert call active.

restart

kernelopts(version)

`Maple 2021.2, X86 64 LINUX, Nov 23 2021, Build ID 1576349`

interface(typesetting = extended)

with(LinearAlgebra)

U := `<,>`(u1, u2)

Vector[column](%id = 36893628195279574668)

K := Matrix(2, 2, symbol = k)

Matrix(%id = 36893628195279567316)

NULL

Q := `%.`(K, U)

`%.`(Matrix(%id = 36893628195279567316), Vector[column](%id = 36893628195279574668))

InertForm:-Display(Q, 'inert' = false)

0, "%1 is not a command in the %2 package", _Hold, Typesetting

value(Q)

Vector[column](%id = 36893628195279541660)

NULL

Download inert_matrix_products_M2021.mw

@abert Preben's procedure returns the name of its local z. That is sometimes called an escaped local.

restart;

f := proc()
 local z;
 z := 2;
 return 'z';
end proc:

Q := f();

z

eval(Q,1), Q;

z, 2

type(eval(Q,1), `local`);

true

addressof(eval(Q,1));

36893628155892795900

# in contrast to the global z
addressof(:-z);

36893628155892795612

Download escaped_local.mw

As Christian mentioned, the means by which your procedure f evaluates that name z is the same means as for your procedure h, ie. because in both cases the unevaluated name was passed in as the argument.

You mentioned "lexical scope".  Consider the following contrasting example, in which procedure g gets a value for z via lexical scoping. Perhaps you were thinking of something like this, when you wrote of your procedure g, "After all, its definition is within the lexical scope of z."

restart;

f := proc()
  local z, g;
  g := proc()
    printf("g says: z evaluates to %a.\n", z);
  end proc;
  z := 2;
  g();
  return 'z', [op(7,eval(g))], ToInert(eval(g))
end proc:

R := f();

g says: z evaluates to 2.

z, [z, z], _Inert_PROC(_Inert_PARAMSEQ(), _Inert_LOCALSEQ(), _Inert_OPTIONSEQ(), _Inert_EXPSEQ(), _Inert_STATSEQ(_Inert_FUNCTION(_Inert_ASSIGNEDNAME("printf", "PROC", _Inert_ATTRIBUTE(_Inert_EXPSEQ(_Inert_NAME("protected", _Inert_ATTRIBUTE(_Inert_NAME("protected"))), _Inert_NAME("_syslib")))), _Inert_EXPSEQ(_Inert_STRING("g says: z evaluates to %a.
"), _Inert_LEXICAL_LOCAL(1)))), _Inert_DESCRIPTIONSEQ(), _Inert_GLOBALSEQ(), _Inert_LEXICALSEQ(_Inert_LEXICALPAIR(_Inert_NAME("z"), _Inert_ASSIGNEDLOCALNAME("z", "INTPOS", 36893628209820994140))), _Inert_EOP(_Inert_EXPSEQ()))

eval(R,1)[1];

z

addressof(eval(R,1)[1]);

36893628209820994140

addressof(:-z);

36893628209820993756

Download lexical_ex.mw

Note. op(7,eval(g)) is the lexical table of the procedure assigned to g, as mentioned on the Help page for topic proc.

Your original example's procedure g, however, has an empty lexical table, and does not get a value for z via lexical scoping. It gets it because the reference was actually passed.

Fwiw, illustrating six free variables, and all integer solutions:

[k[6] = 22*k[1]-3*k[2]-k[3]-4*k[4]+4*k[5]+3*k[10],
 k[7] = -5*k[1]+k[2]+2*k[3]+10*k[4]-k[5]-k[10],
 k[8] = -14*k[1]+k[2]-k[3]-3*k[4]-3*k[5]+k[10],
 k[9] = -4*k[1]-k[3]-4*k[4]-k[5]-4*k[10]]

That can be had by,

simplify(combine(solve(evalc(convert(eqs,radical)),
                {k[6],k[7],k[8],k[9]}))):

You wrote the k[1]..k[6] are the "unknowns". The following produces a rational solution. This is similar to what Kitonum showed, but without requiring the unguaranteed steps of evalf & identify.

simplify(combine(solve(evalc(convert(eqs,radical)),
                       {k[7],k[8],k[9],k[10]})));

Naturally, you can scale (here, by 3) to get purely integer solutions.

The following would remove spurious imaginary components (eg. small imaginary artefacts due to floating-point roundoff error).

It will also remove remaining complex (ie. non-real) results, so that max can succeed.

temp := [solve(f=0,x)]:

max(select(type,
           simplify(fnormal(evalf(temp)),
                    ':-zero'),
           realcons));

Why haven't you shown us your actual equations, or uploaded and attached a worksheet that produces them? That would make it easier for people to help you.

The simplest way to get the result is to use the solve command.

The way in which the optional second argument is passed to solve controls the form in which the result is returned (ie. as y=value, or just the value).

restart;

eq := (3*y - 2)/3 + (2*y + 3)/3 = (y + 7)/6;

(5/3)*y+1/3 = (1/6)*y+7/6

solve(eq, {y});

{y = 5/9}

solve(eq, y);

5/9

solve(eq);

5/9

Download solve_lin.mw

You could also get a so-called step-by-step solution shown for this class of linear problem.

This is a verbose illustration of how one could solve it by hand. (Maple's solve command has its own methodology, and I'm not sure whether you are actually asking how that works, internally.)

restart;

eq:=(3*y - 2)/3 + (2*y + 3)/3 = (y + 7)/6;

(5/3)*y+1/3 = (1/6)*y+7/6

Student:-Basics:-LinearSolveSteps(eq, y);

"[[`%+`(`%*`(`%/`(5,3),y),`%/`(1,3))=`%+`(`%/`(y,6),`%/`(7,6))],[`%+`(`%*`(`%/`(5,3),y),`%/`(1,3),-`%/`(1,3)-`%/`(y,6))=`%+`(`%/`(y,6),`%/`(7,6),-`%/`(1,3)-`%/`(y,6)),("Subtract" (1)/(3)+(y)/(6) "from both sides")],[`%+`(`%*`(`%/`(5,3),y),`%/`(-y,6))=`%+`(`%/`(7,6),`%/`(-1,3)),("Simplify")],[`%+`(`%/`(5 y,3),`%/`(-y,6))=`%+`(`%/`(7,6),`%/`(-1,3)),("Multiply fraction")],[(3 y)/2=`%+`(`%/`(7,6),`%/`(-1,3)),("Add terms")],[(3 y)/2=5/6,("Add terms")],[`%*`(3/2 y,2)=`%*`(2,5/6),("Multiply rhs by denominator of lhs")],[3 y=5/3,("Simplify")],[`%/`(`%*`(3,y),3)=`%/`(5/3,3),("Divide both sides by" 3)],[y=5/9,("Simplify")]]"

Download SBLSS.mw

restart;

expr:= sqrt(alpha^2+k^2)*(-sqrt(alpha^2+k^2)*exp(k*z0)+k*exp(sqrt(alpha^2+k^2)*z0))
       /((-alpha^2-k^2)*exp(k*z0)+exp(sqrt(alpha^2+k^2)*z0)*sqrt(alpha^2+k^2)*k);

(alpha^2+k^2)^(1/2)*(-(alpha^2+k^2)^(1/2)*exp(k*z0)+k*exp((alpha^2+k^2)^(1/2)*z0))/((-alpha^2-k^2)*exp(k*z0)+exp((alpha^2+k^2)^(1/2)*z0)*(alpha^2+k^2)^(1/2)*k)

radnormal(expr);

1

Download simpl_ex.mw

I will submit a bug report against simplify.

The simple answer to Q1 and Q2 is no, unless you unprotect and reassign a new procedure to the global WARNING.

Q1. The attachment below shows one rough way to reassign to WARNING that will add the name of the calling procedure. (I just did a slight modification of a bit of a package I wrote for redefining userinfo to send its messages to a TextArea component.)

Q2. You could modify and extend that implementation to make command specific suppression possible. Since the procedure redefinition below has access to the name of the caller then that could be tested against a stored table/record. And so you use some name for storing that, eg. warnings[f]:=false or what have you. Alas I don't have time for that right now.

Q3. Likely yes, programmatically manipulating the saved .mw file and writing out to a new .mw file. But that approach would require time to implement.

restart;

Set := proc(id::string) local i, orig;
  global __T, __origW;
  if not assigned('__origW') then
    __origW := eval(:-WARNING);
    unprotect(':-WARNING');
    :-WARNING :=
        proc(n)
          local fullstack, msg, whereami;
              fullstack := debugopts('callstack');
              if convert(eval(fullstack[5],1),`global`) = ':-try_method' then
                whereami := "";
              else
                whereami := cat(fullstack[5], ": ");
              end if;
              msg := convert(cat(whereami,
                                 StringTools:-FormatMessage(args)),
                             string);
              __T[msg] := fullstack[5];
          print(INTERFACE_WARN(1,msg));
        end proc;
    protect(':-WARNING');
  end if;
  return NULL;
end proc:

 

Now, two examples of the usual behavior.

 

WARNING("hey %1", sqrt(x));

Warning, hey x^(1/2)

f := proc() WARNING("hey %1", sqrt(x)); end proc:
f();

Warning, hey x^(1/2)

 

Now, we'll replace the WARNING command, and re-execute
those examples.

 

Set():

 

WARNING("hey %1", sqrt(x));

Warning, TopLevel: hey x^(1/2)

f := proc() WARNING("hey %1", sqrt(x)); end proc:
f();

Warning, f: hey x^(1/2)

 

We stored the information.

 

eval(__T);

table( [( "TopLevel: hey x^(1/2)" ) = TopLevel, ( "f: hey x^(1/2)" ) = f ] )

Download WARNING_redefn.mw


Of course, you could modify or adjust that as needed. You could also unassign that table of results whenever convenient, etc.

Your syntax for calling the plot command seems quite wrong. I cannot imagine what you intended by l = 5*_8, except possibly as a typographical mistake where you intended the range l = 5..8.

Your syntax for invoking solve is wrong. That command does not take an argument of the form name=range.

Note that the error messages you showed do indicate these mistakes. You could also reference the allowed calling sequences of those commands on their respective help pages.

And there is not an explicit exact solution. Therefore I suggest calling fsolve instead here, to get a floating-point result.

plot(cos(l)*cosh(l) - 1, l = 5..8);

fsolve(cos(l)*cosh(l) - 1, l = 5..8);

7.853204624

Download rf_syntax.mw

I don't understand what your intention is, when you write "k=1..4".  The expression cos(k)*cosh(k)-1 does not have a real root for k between 1 and 4.

Here's one way to handle your examples,

restart;

 

R := expr -> subsindets(expr,`+`,
       proc(ee)
         local u:=selectremove(type,ee,specfunc(f));
         if u[1]<>0 then
           f(subsindets(u[1],specfunc(f),op))+u[2];
         else
           u[2];
         end if;
       end proc):

 

R( f(A) );

f(A)

R( f(A)+f(B) );

f(A+B)

R( f(A)+f(B)+f(C) );

f(A+B+C)

R( sin(x)+10*exp(x)/13+cos(x) );

sin(x)+(10/13)*exp(x)+cos(x)

R( sin(x)+f(A)+10*exp(x)/13+cos(x) );

sin(x)+f(A)+(10/13)*exp(x)+cos(x)

R( sin(x)+f(A)+f(B)+10*exp(x)/13+cos(x)+f(C)+f(10*C) );

f(A+B+11*C)+sin(x)+(10/13)*exp(x)+cos(x)

Download subsindets_examp.mw

You could make that more general by having the name (eg. f) be an additional parameter.

Here are some answers.

note: I removed the call to assume. I never use assume if I can get by without it.  I prefer to get by utilizing assuming instead, since it can be used in a more targeted manner. Or, as in this case, one can get by with performing so-called simplification with side-relations (see below).

restart; interface(showassumed = 0)

U := Matrix(2, 2, {(1, 1) = a, (1, 2) = b, (2, 1) = -LinearAlgebra:-HermitianTranspose(b), (2, 2) = LinearAlgebra:-HermitianTranspose(a)})

Matrix(%id = 36893627967393143972)

Is the "with linearAlgebra" statement below always and strictly necessary for a simple 2x2 inverse?

Its dizzying betwween Linalgebra-generic and non generic, Deep learning, and so many packages that have a matrix inverse function: How to choose?

Ans: You don't need any of those specialized packages or subpackages. You
can simply utilize the basic LinearAlgebra package (or raise your Matrix to power -1).

with(LinearAlgebra)

 The assume(a*a + b*b = 1) above seems to do nothing below.     how can we make the assumption stick?

Ans: If you want to "simplify" by performing a substitution then you can use so-called simplify with side-relations.
        See the help page for topic  simplify,siderelations

D1 := Determinant(U); simplify(D1, {LinearAlgebra:-HermitianTranspose(a)*a+LinearAlgebra:-HermitianTranspose(b)*b = 1})

a*conjugate(a)+b*conjugate(b)

1

Why does Inverse fail? is the modulus mandatory?

Ans: You were using an incorrect command name in your attempt at calling LinearAlgebraL-MatrixInverse.
You could also raise U to the power -1.

`#msup(mi("U"),mo("&dagger;"))` := MatrixInverse(U)`#msup(mi("U"),mo("&dagger;"))` := 1/U

Matrix(2, 2, {(1, 1) = conjugate(a)/(a*conjugate(a)+b*conjugate(b)), (1, 2) = -b/(a*conjugate(a)+b*conjugate(b)), (2, 1) = conjugate(b)/(a*conjugate(a)+b*conjugate(b)), (2, 2) = a/(a*conjugate(a)+b*conjugate(b))})

Matrix(%id = 36893627967393110724)

Is it possible to denote the usual inverse with the superscript -1?

Ans: right-click on U^-1 and select 2-D Math -> Convert To -> Atomic Variable
That turns it into a special name (which happens to pretty-print as you wish), to which
you can make the usual kind of assignment.

`#msup(mi("U"),mrow(mo("&uminus0;"),mn("1")))` := MatrixInverse(U)

Matrix(%id = 36893627967393103372)

 The assume(a*a + b*b = 1) above seems to do nothing below

Uinv := MatrixInverse(U); simplify(Uinv, {LinearAlgebra:-HermitianTranspose(a)*a+LinearAlgebra:-HermitianTranspose(b)*b = 1})

Matrix(2, 2, {(1, 1) = conjugate(a)/(a*conjugate(a)+b*conjugate(b)), (1, 2) = -b/(a*conjugate(a)+b*conjugate(b)), (2, 1) = conjugate(b)/(a*conjugate(a)+b*conjugate(b)), (2, 2) = a/(a*conjugate(a)+b*conjugate(b))})

Matrix(%id = 36893627967308692644)

The curly bracket seems to do what I expected Assuming would do (in-line format).

I'd also expect {} to mean a set!! Why is there no mention of {} in the Simplify documentation?

Ans. It is indeed documented! There is a "See Also" cross-reference as well as a hyperlink to
the auxilary Help page for topic  simplify,siderels  on the simplify Help page.

simplify(Uinv, {LinearAlgebra:-HermitianTranspose(a)*a+LinearAlgebra:-HermitianTranspose(b)*b = 1})

Matrix(%id = 36893627967308683252)

help("simplify,siderelations")

Below I use r_t. Can one use  r' (as in transformed r) and not mean it to be the derivative?

Ans: right-click on r' and select 2-D Math -> Convert To -> Atomic Variable
note: you need to do this each time you input r' (or you could assign it to some name,
to get the effect only in the output).

`#mrow(mi("r"),mo("&apos;"))` := U.(Vector(2, {(1) = x+I*y, (2) = z}))

Vector[column](%id = 36893627967308679516)

assume(alpha > 0)

Why does it cc alpha despite the assume statement? and why zero-bar?

Ans: Because subs does not evaluate by default, after performing the substitution.
A better approach here is to use eval.

note. It is generally useful to have some command that does not evaluate following
substitution, so that subsequent operations can be performed on the intermediate,
unevaluated expression (which otherwise might change before we had the chance).
In other words, it's useful in general that subs and eval both exist and behave differently.

 

subs(a = exp(I*alpha*(1/2)), b = 0, `#mrow(mi("r"),mo("&apos;"))`); `~`[eval](%)

Vector(2, {(1) = exp(((1/2)*I)*`&alpha;`)*(x+I*y), (2) = -conjugate(0)*(x+I*y)+conjugate(exp(1))^(((1/2)*I)*`&alpha;`)*z})

Vector[column](%id = 36893627967308664452)

eval(`#mrow(mi("r"),mo("&apos;"))`, [a = exp(I*alpha*(1/2)), b = 0])

Vector[column](%id = 36893627967308649044)

NULL

Download matrix_ops_Qs_ac.mw

The following approach is not fancy, but hopefully you'll find it understandable.

The basic idea here is to form a list of all the indices of the table, and then pare that down according to whether the corresponding values are NULL.

T := table([1 = NULL, 2 = NULL, 3 = NULL, 4 = NULL, 5 = NULL, 6 = NULL, 7 = 5, 9 = NULL, 8 = NULL, 11 = 4, 10 = NULL, 13 = NULL, 12 = NULL, 15 = 9, 14 = NULL, 18 = NULL, 19 = 8, 16 = 9, 17 = NULL, 22 = 9, 23 = NULL, 20 = NULL, 21 = 8, 27 = NULL, 26 = 8, 25 = 4, 24 = NULL, 31 = NULL, 30 = 9, 29 = NULL, 28 = 9, 36 = NULL, 37 = 9, 38 = 9, 39 = NULL, 32 = 5, 33 = NULL, 34 = NULL, 35 = NULL, 45 = NULL, 44 = NULL, 47 = NULL, 46 = NULL, 41 = 8, 40 = NULL, 43 = NULL, 42 = NULL, 54 = NULL, 55 = NULL, 52 = NULL, 53 = NULL, 50 = NULL, 51 = NULL, 48 = 5, 49 = 9, 60 = 8, 59 = NULL, 58 = 7, 57 = 7, 56 = NULL]):
 

select(i->T[i]<>NULL, [indices(T,nolist)]);

[7, 11, 15, 19, 16, 22, 21, 26, 25, 30, 28, 37, 38, 32, 41, 48, 49, 60, 58, 57]

Download table_lk.mw

ps. There are even fancier ways, including some using newly introduced syntax. But the above should work in most/many old versions.

Please see the attached, which I believe is as much as can be recovered from your original attachment. (This is much more than the GUI itself recovers.)

Assignment2_ac.mw

There may now be four or five removed (invalid) 2D inputs:
1) just after, "We only need to consider the eigenvalues of the matrix A of the modelled system"
2) just before "From A__1 we have the first eigenvalue"
3) Just before, "The roots of the polynomium"
4) Just before, "To find the two eigenvalues we solve"
5) Just before, "The roots of the polynomium"

note: I think you might also have some misspellings, eg. "polynomium" for "polynomial", and "Luaponov" for "Lyaponov".

note: Of course, I will add this example to my previous bug reports of similar, reported problems.

note: There is some evidence that use of the Matrix palette in non-executable 2D Math might be related to the underlying GUI problem.

It looks as if there is no multiplication sign (or space, for implicit multiplication with 2D Input) before the brackets in the terms that look like,

   a(x+I*y)  ,  b(x-I*y) 

In that case those terms would be function calls (of a and b), rather than products.

Similarly the terms that look like bz , az would be just two-letter names, rather than products.

It's difficult to tell for sure because you haven't upload and attached your actual worksheet (green up-arrow in the Mapleprimes editor).

First 50 51 52 53 54 55 56 Last Page 52 of 336