Carl Love

Carl Love

28020 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

The mul command will work for explicitly specified values of n. But to express the product for arbitrary n, you need to use product. Note how I iterate through the odd denominators only by using 2*a+1. Unlike (recent versions of) mul, the product command will not accept a "step" such as 2 as a 3rd argument. 

h:= x-> sin(x)/x:
J:= Int(product(h(x/(2*a+1)), a= 0..n), x= 0..infinity) 
    assuming n::nonnegint; 

Maple won't evaluate that integral; or at least it wouldn't do it in an amount of time that I was willing to wait. But it will do it for specified nonnegative integer values of n:

value(eval(J, n= 7));

For every n that I tried, it returned Pi/2. I suspect that there is a fairly easy proof that it's always Pi/2.

This seems too obvious---you must have considered it yourself: Is there any reason to not do simply

max(abs~(F-G))

where is the matrix for f and G is the matrix for g?

Aposthropes (ASCII code 39) are not special in strings. The only special ASCII characters are double quotes (ASCII 92) and backslash (ASCII 34). These can also be included in strings; they simply need to be escaped with backslash if they're hard-coded.

The error message that you show is typical when using sum, and you mentioned sum in your title. So which did you actually use? The correct command is add, not sum. Furthermore, the eval and indexing are not needed. You should be able to replace the entire command with

evalDG(add(L));

Divide the integration interval symbolically, like this:

(h,f):= (x-p, x^2+p*x):  (a,b):= (0,10):
sol:= solve(h = f, x);
add(int~([f,h,f], x=~ [a..sol[2], sol[2]..sol[1], sol[1]..b]));
simplify(%);
                              (3/2)              
              1 / 2          \               1000
              - \p  - 6 p + 1/      + 50 p + ----
              6                               3  

This solution is still correct even if the solution points sol are not in the interval 0..10.

Any rtable (i.e., ArrayMatrix, or Vector) can be shuffled with randperm without any need to directly access or refer to its entries or any need to directly refer to its dimensions with this short procedure:

Shuffle:= (R::rtable)->
    R[(combinat:-randperm@`[]`@`$`)~([rtable_dims](R))[]]
:

 

It looks to me as if it did name the function A. And what is there to optimize in returning a 2x2 matrix of zeros? You can just ignore those warnings.

@adel-00 You wrote:

  • u := proc (x, t) options operator, arrow; tanh(2*Pi-t-x) end proc;
    v := proc (x, t) options operator, arrow; tanh(2*Pi+t+x) end proc;
    A := 1/4*(-2*u(x, t)*(diff(v(x, t), x))+2*beta1*u(x, t)*(diff(u(x, t), t, t))+beta2*u(x, t)^2*(u(x, t)^2+v(x, t)^2)-2*alpha1*u(x, t)*(diff(v(x, t), t, t, t))-alpha2*u(x, t)*(u(x, t)^2+v(x, t)^2)*(diff(v(x, t), t))+2*v(x, t)*(diff(u(x, t), x))+2*beta1*v(x, t)*(diff(v(x, t), t, t))+beta2*v(x, t)^2*(u(x, t)^2+v(x, t)^2)+2*alpha1*v(x, t)*(diff(u(x, t), t, t, t))+alpha2*v(x, t)*(u(x, t)^2+v(x, t)^2)*(diff(u(x, t), t)));
    f := (x,t) -> A:
    r1:=int(int(A,x=-10..10),t=-3..3,numeric):

Maple is attempting a symbolic integration on the inner integral because only the outer integral specifies numeric. This is what takes a long time. To appreciate the complexity of your A consider that expand(A) has 3730 terms (although I'm not saying that that is how the symbolic integrator is looking at it).

To integrate both integrals numerically, you need to factor out the symbolic constants. This is fairly easy to do:

Coeffs:= proc(e::algebraic, V::{list,set}(name))
local T, C:= coeffs(e, V, T);
    table([T]=~[C])
end proc
:
V:= [alpha1, alpha2, beta1, beta2]:
C:= Coeffs(A, V):
r1:= add(v*int(C[v], [x= -10..10, t= -3..3], numeric), v= [indices](C, nolist));
        r1 := -11.78614736 - 7.805610537*alpha2 + 0.6218523429*alpha1 + 
              100.4082421*beta2 - 7.650147471*beta1

This result only takes about a second.

By the way, your command f:= (x,t)-> A is unnecessary and also incorrect. If it were needed, the correct command would be f:= unapply(A, [x,t]).

[Edit: Code updated to accomodate terms with mulitple symbolic coefficients. Also, my earlier code wasn't reporting the constant term.]

I would ignore that help page statement about algsubs being a generalization. It is a highly specialized command that should only be used when it's specifically needed (which is rarely). In general, use subs or eval and do not even think of using algsubs. Also, subs and eval are far more efficient.

Here is a way that uses the StyleVertex command. There are many attirbutes other than color that could be used to distinguish the vertices. If you do use color, there are many ways that the colors can be chosen.

ShowPartition:= proc(
    G::Graph,
    P::{list, set}(({list, set})({integer, symbol, string}))
)
local n:= max(nops(P), 2), k, B;
    for k,B in P do
        GraphTheory:-StyleVertex(
            G, B, 
            ':-color'= ':-COLOR'(':-HSV', .8*(k-1)/(n-1), 1., 1.)
        )
    od;
    return
end proc
:
GT:= GraphTheory:
G:= GT:-RandomGraphs:-RandomGraph(9, .5, connected);
 G := Graph 2: an undirected unweighted graph with 9 vertices 
    and 18 edge(s)

GraphTheory:-ChromaticNumber(G, 'P');
                               4

ShowPartition(G,P);
GraphTheory:-DrawGraph(G);

table is not the best data structure to use for this.  But if you're going to use a table, here's another way:

T:= table([.6, 1.2, 2.0, 3.3, 4.1, 5.0, 5.5, 5.8]):
plot([lhs-1, rhs]~([entries](T, pairs, indexorder)));

 

Both the commands plot() and plot([]) produce an empty plot with no warning. So the following procedure does what you describe:

MyPlot:= proc(X::list(realcons), f)
local x, n:= nops(X);
    plot(( 
        if n = 1 then 
            [[X[], f(X[])]], style= point, symbolsize= 20
        elif n > 1 then 
            CurveFitting:-Spline(X, f~(X), x), x= (min..max)(X)
        else
        fi), _rest
    )
end proc
:
MyPlot([1,2,3], sin);

I may need to adjust that for earlier versions of Maple.

I think that you may have the idea that you first define an empty plot, and then add things (like points or spline curves) to it. The plot command doesn't support such object-oriented methods, although it would be possible to implement something like that.

The situation with W1 and W2 is clear, and it'll be better handled by piecewise than by if:

W1:= h-> piecewise(h < 1, 1, 2);
W2:= h-> piecewise(h < 1, 3, 4);

Within the main function, use W1(h) and W2(h).

But how are tN, and h_TOT handled?

There are many ways to do it, here's one:

for i to 9 while F[i]+F[i+1] < 20 do od;

print(`if`(i > 9, Testbestanden, Durchgefallen));

Notes:

  1. od is the same as end do. It's just a personal choice.
  2. This loop has no statement in its body (or you could say it has the null statement). That's not a problem. 
  3. We need to know why the loop terminated. If i > 9, it finished normally; otherwise the while condition failed for some i.
  4. `if` can be used as a function using the syntax shown. The quotes are mandatory.

Sets are automatically sorted when they are created in a way that is most efficient for lookups. Indeed there is no way to prevent this sorting. 

You should store your 30-digit numbers as integers, so that they'll fit into two 64-bit words.

There's no need to directly use membership testing. Just take intersections of X with subsets of Y until a nonempty intersection is obtained or Y is exhausted. 

First 81 82 83 84 85 86 87 Last Page 83 of 395