Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 359 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Use P[A]:= 0.3, etc. For conditionals, use P[A,B].

The syntax f1(p,b):= ... is not the correct way to define a function in Maple. The correct syntax is 

f1:= (p,b)-> 1/(p^2 + b^2)^2;

Then enter the integral as 

T1pbm:= int(q*f1(q,b)*ln((p+q)^2 +m^2), q= 0..infinity) assuming real;

Notice that int is with a lowercase i. The integral will take 5-10 seconds. Then do the same for the second integral. It will take several minutes.

Since the integrals will be done, the calls to Parts will be superfluous. Since your variables have no numeric values, the calls to evalf are superfluous. Finally, the constant Pi is spelled with a capital P in Maple; pi is just another variable.

The equals sign is not the assignment operator in Maple, so your line in the for loop is not setting the values of A[0] and A[1]. The assignment operator is colon-equals. So, you simply need to change the line in the for loop to 

A[n] := int(...)

Here's a completely different algorithm. By evaluating the equation

f - add(c[k]*g||k, k= 1..m) = 0  (*)

at different exact random numeric evaluations of the variables xy, ..., we obtain a set of constant-coefficient linear equations in unknowns c[1], ..., c[m]. This system is solved. If there's no solution, then there's no linear combination (guaranteed). If there's a solution, it's used in a symbolic attempt to reduce (*) to 0=0. If this is possible, then it's a linear combination (guaranteed).

This algorithm works over a class of expressions much larger than polynomials, and it handles transcendental coefficients. Here it is:

LinearCombo:= proc(B::list(algebraic), T::algebraic)
local
     V:= indets([B,T], And(name, Not(constant))),
     nV:= nops(V),
     c, #linear coeffiecients
     k, K, #indices
     nB:= nops(B),
     Eq:= add(c[k]*B[k], k= 1..nB) - T,
     Eqs,
     S, Z, R
;
     for K to 2 do
          Eqs:= {'eval(Eq, V=~ {'rand()' $ nV})' $ nB};
          if nops(Eqs) = nB then break end if;
     end do;
     if K = 3 then
          error "Almost certainly, all expressions are constant"
     end if;
     S:= solve(Eqs);
     if S=[][] then return false end if;
     Z:= indets(rhs~(S), And(name, Not(constant)))=~ 0;
     S:= eval(S,Z) union Z;
     R:= is(eval(Eq,S) = 0);
    `if`(R, eval([c[k] $ k= 1..nB], S), R)    
end proc:

The procedure is called liked this:

LinearCombo([y^2-y, y+x^2], x^2+y^2);

Other than errors for syntactically incorrect input or system problems, it returns one of four things:

  1. a list of coefficients that make a linear combination
  2. false, indicating that no linear combination exists
  3. rarely, FAIL, indicating the inability of is to simplify the coefficients
  4. the error message Almost certainly, all expressions are constant.

A positive result (1) is guaranteed correct (it's been verified with is). A false result can be wrong with a small probability if there is a highly convoluted relationship among coefficients containing transcendentals that is incorrectly labelled false by is. The result FAIL, of course, can never be wrong, and it represents a failure of is (see ?is). If the error "Almost certainly, all expressions are constant" is returned, there is an infintesimal probability that two sets of m random evaluations of the variables just happened to pick values such that an equation was redundant.

Comments welcomed, especially attempts to break the program or interesting experiences with transcendental functions, transcendental coefficients, trigonometric and other identities.

You simply need to enclose the variable name in curly braces in the call to solve: Change 

solve(ics[i], v[i])

to

solve(ics[i], {v[i]})

Here's an efficiency/stylistic point, not an error: Unless you're planning on using the values solved[i] later, there's no point in storing them in variables. It just creates uncollectable garbage. Instead, combine the solve and assign:

for i to 3 do assign(solve(ics[i], {v[i]})) end do

 

It is an unfortunate nuance of the syntax that any reasonable attempt to create an empty Matrix using square brackets creates a Matrix with one empty row. That is, it has one row and zero columns. Note that 

ColumnDimension([[1]]) <> ColumnDimension([[]]),

the former being 1 and the latter 0.

As far as I can tell, the only two reasonable ways to create a truly empty Matrix are

Matrix()Matrix(0), etc.

or the more primitive

rtable(1..0, 1..0, subtype= Matrix).

These will create Matrices with zero rows and zero columns.

You wrote that it is possible to write 3*h(2)+D(h)(2) as (Psi(2)+gamma)*h(2)+D(h)(2). That is not true: Psi(2) = 1 - gamma, so Psi(2)+gamma = 1, not 3. So, the expansion of Psi(2) as 1 - gamma is irrelevant in this case. But if you did want to turn off the automatic expansion of Psi(positive rational), use 

map2(Cache:-RemovePermanent, Psi, [[1],[2]]);

`Psi/constant`:= `Psi/constant`[1], 0, `Psi/constant`[3]:

If you want to also turn off the expansion of Psi(positive rationalthat is done by the expand command, use

expand(expandoff()):  expandoff(Psi):

Now execute the residue command:

residue((Psi(-z)+gamma)^2*h(z), z= 2);

     2*h(2)*Psi(3)+(D(h))(2)+2*h(2)*gamma

I see that you changed your Question, changing gamma to Eulergamma. This is wrong. Eulergamma is meaningless to Maple. The Euler constant is known to Maple simply as gamma.


Edit: Answer corrected due to a problem discovered by Markiyan below.

 

You were on the right track with your idea of guessing b. We just have to make that automatic and systematic. Imagine a real-valued function RSS of a real variable bRSS returns the residual sum of squares from doing a linear regression on the logarithms to find the values of A and c. (That linear regression is done by the command Statistics:-PowerFit; you don't need to take the logarithms yourself.) Then we use Maple's numerical minimizer to find the b that minimizes RSS.

I'll assume that you can come up with lower and upper bounds for b. If not, I'll need to modify my procedure a little. In the procedure below, the first argument is your two-column Matrix, and the second argument is the range of possible b values in the form min_val..max_valI haven't tested this procedure because I don't have any suitable data. If you send your Matrix and your b range, I'd be happy to test it.

Since t-b must be strictly positive, the upper bound for b must be strictly less than the minimum value of t. If you violate this, you'll get an error message.

RecenteredPowerFit:= proc(TW::Matrix, b_range::range(realcons))
local
     T:= TW[..,1], W:= TW[..,2],
     b:= Optimization:-NLPSolve(
          b-> Statistics:-PowerFit(T-~b, W, output= residualsumofsquares),
          b_range, method= branchandbound, objectivetarget= 0
     )[2][1],
     Res:= Statistics:-PowerFit(T-~b, W)
;
     ['A' = Res[1], ':-b' = b, 'c'= Res[2]]
end proc:

If you want the symbolic derivative to be defined at the knots, then the slopes on either side of the knot need to match exactly. Matching to 14 decimal places is not exactly. To get an exact match, use exact numbers in the input: change 2.2 to 11/5 and change 1.8 to 9/5. If you make this simple change, there'll be no undefined points for the derivative. These subleties would not make any difference if you were using numeric differentiation.

By the way, the syntax x(t):= ... is a substandard way to define a function in Maple. It can lead to trouble. The correct way is x:= t-> ....

 

Picking up from the end of your worksheet:

ex:= expand(%[]);
coeff(ex, w, -1)/w + coeff(ex, w, -2)/w^2;

It's a simple procedure, similiar to the Univariate that I wrote for you last night. We extract the names with indets and then subtract the parameters, which are passed as an argument.

Variables:= (e, p::{set,list,rtable}(name))->
     indets(e, And(name, Not(constant))) minus convert(p,set)
:

Usage:

Variables([(a-1)*x*y^2-b+x, x-y+x^2-c], [a,b,c]);

     {x,y}

The first argument can be anything, not necessarily a list of polynomials. The second argument could just as well be {a,b,c} or <a,b,c>. Indexed variables and parameters (such as a[0] or x[i]) are allowed without the need to declare the subscripts in the set of parameters.

We need to check that the expression has one variable and that it's a polynomial with respect to that variable.

TypeTools:-AddType(
     Univariate,
     proc(P)
     local x:= indets(P, And(name, Not(constant)));
          nops(x) = 1 and P::polynom(anything,x[])
     end proc
);

With this, we can run checks like the following, each of which returns true or false.

type(x^2+1, Univariate);
type(x*y, Univariate);

When type checks occur inside other Boolean expressions, they can be done with the `::` operator:

if (x^2+1)::Univariate then ... end if;

First off, I have to say that I don't know what it means when an integral's variable of integration is also used in the limits of integration, especially when the you take the derivative of that integral with respect to that variable. I don't know what it means mathematically, nor do I know how Maple interprets it (the derivative part is especially confusing to me). However, Maple seems to not be bothered by it, so I'll work with it to give you an Answer.

We need to do the inner integral also with capital I so that they are done numerically. The differentiation will still be done symbolically before the integration. We will pass the epsilon option to all the integrals to reduce the requested accuracy. But this has to be done after the differentiation because extra integral arguments cause confusion for diff. That is what the subsindets command is doing. We cannot use method _d01ajc. I'll use the default method.

H3p:= proc(ms::algebraic, b::numeric, eps::positive:= 0.5*10^(1-Digits))
local x:= indets(ms, And(name, Not(constant))), D;
     if nops(x)>1 then
          error "1st argument must be an expression of at most 1 variable"
     end if;
     x:= x[];
     D:= diff(ms,x);
     evalf(
          subsindets(
               Int(
                    diff(
                         D*Int((-b*x+1)*Int(D^2, x= 0..x), x= 1..x),
                         x
                    )*ms,
                    x= 0..1
               ),
               specfunc(anything, Int),
               J-> Int(op(J), epsilon= eps)
          )
     )
end proc;

This procedure will give you five digits of precision in 13 minutes and ten digits in 25 minutes.

CodeTools:-Usage(H3p(ms, 0.7, .5e-5));

     memory used=58.05GiB, alloc change=488.00MiB, cpu time=12.60m, real time=12.45m, gc time=2.01m
     10.7274995619619 + 2.56038670633894*10^(-8)* I

 

It is simply

Int(t^2*exp(-s*t), t= 0..3);

which can be done by two easy integration by parts. (For hand computation, I use the "tabular integration" method.)

You simply need some square brackets to enclose the list of plots:

plot([plo[1], plo[2]]);

You can plot all the solutions together on the same axes with

plot(convert(plo, list));

First 258 259 260 261 262 263 264 Last Page 260 of 395