Carl Love

Carl Love

28070 Reputation

25 Badges

13 years, 29 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

The reason that it's taking so long is that your inner integrals are symbolic, and Maple is not finishing that symbolic integration. Maple can do your innermost integral symbolically in a few seconds. The result is about three screens long. The next layer out takes longer; it may be the one that doesn't finish.

For the vast majority of Maple commands (procedures), the arguments are evaluated before being passed. For example, if your call were simplified to

int(int(f(x,y), x= 0..g(y)), y= 0..b, numeric);

that inner integral would be performed symbolically before the numeric integration is even started.

There's no point in trying numeric integration when you have symbolic parameters. You have k, l, a, and b.

Maple has an alternate simplified notation for multiple integrals that will help you avoid the problem of premature evaluation of inner integrals, and also vastly simplify the parentheses needed for your four-deep integral. This notation works for both numeric and symbolic integrals. In the alternate notation, my integral above becomes

int(f(x,y), [x= 0..g(y), y= 0..b], numeric);

 

Because Vector is an active procedure as well as a type and metatype, the procedure call Vector(Element) needs to be prevented. If you want to do this and also use TypeTools:-Exists, then you need two pairs of unevaluation quotes on Vector:

TypeTools:-AddType(ExpandedLine, ''Vector''('Element'));

(That's not double quotes; it's two sets of single quotes.) I can't tell you a concrete rule by which I know to use two sets of quotes; however, I've tested it, and it works.

Unlike arrays, two lists L1 and L2 can be checked for equality as a whole, i.e., without needing to do it elementwise:

if L1=L2 then "They're equal." else "They're not equal." end if;

You asked a very important question that perplexes many new Maple programmers. The best way to create a list element by element when you do not have foreknowledge of the final number of elements is to temporarily store the elements in a Maple hash table and then convert that table to a list when you're done. Like this:

Base3:= proc(n::nonnegint)
local r, R:= table(), k, q:= n;
     for k while q > 0 do
          q:= iquo(q, 3, 'r');
          R[k]:= r
     end do;
     `if`(n=0, [0], convert(R, list))
end proc:

You can do the same thing with a dynamically sized rtable. The coding is almost identical, and, as far as I can tell, it is just as efficient:

Base3:= proc(n::nonnegint)
local r, R:= Vector(1), k, q:= n;
     for k while q > 0 do
          q:= iquo(q, 3, 'r');
          R(k):= r
     end do;
     `if`(n=0, [0], convert(R, list))
end proc:

In Maple, a list cannot be initialized; there would be no point since a list cannot be modified at all. (Any examples that you may have seen of lists being modified are faked by the interpreter and are highly inefficient.) A list can be created with its final (and only) entries by

mylist:= [seq(sumsquare(k), k= 1..n)];

An array (or Array) is different from a list; it can be initialized and modified. 

The following procedure uses StringTools:-RegSplit to achieve what you want. You said that you do not need the positions; however, my algorithm necessarily generates the positions, so I thought that I might as well return them also.

RegMatches:= proc(
     P::string, #Regular expression
     T::string  #Text to search
)
uses ST= StringTools;
local
     S:= [ST:-RegSplit(P,T)],
     s,           #one result of above
     p:= 0,       #current position in T
     R:= table(), #return
     m            #a match
;
     for s in S[1..-2] do
          p:= p+length(s);
          ST:-RegMatch(P, T[p+1..-1], 'm');
          R[p+1]:= m;
          p:= p+length(m)
     end do;
     eval(R)
end proc:

Your example:

T:= "variable %1 needs to be of the form %3+2.9 "
    "in order to use routine %2 to find the fizturl":

P:= "%[0-9]+":

RegMatches(P,T);



Also, before you go and re-invent the wheel, check if StringTools:-FormatMessage will do what you need.

Here's another way, not necessarily better, using functional-programming style and, naturally, LinearAlgebra:-RandomMatrix.

P:= (n::posint, m::posint)->
     (x-> (d-> `if`(d[1]=d[-1], x, ``))(convert(x, base, 10)))~
          (LinearAlgebra:-RandomMatrix(n,m, generator= rand(100..999))):

P(10,10);

Despite what Dr Lopez said (which I agree with), you may have your own good reasons for wanting to stick with the VectorCalculus package and for wanting to represent tensors as Maple Matrices. So, I just wanted to show you that the less elegant way that you described is not so bad. Here it is:

<seq(Divergence(VectorField(M[k,..])), k= 1..3)>;

IntTutor is not designed to handle symbolic constants; however, if you hold its hand at each step, you can get an answer for this problem. But what's the point? Are you saying that you want to learn Laplace transforms, yet you don't even know how to integrate exp((a-s)*t) from 0 to infinity? For IntTutor to work, you need to replace the infinity with a finite symbolic constant. I chose gamma below. Then, in the final answer, replace gamma with infinity or a use a limit expression to that effect.

Your syntax has numerous errors: lack of parentheses, using e instead of exp, and others. Here's the corrected syntax:

f:= t-> exp(a*t):
IntTutor(Int(exp(-s*t)*f(t), t= 0..gamma);

If you use disassemble to take apart the expression, you will see that dismantle is showing a truer representation of how the expression is actually stored than ToInert is.

L1:= disassemble(addressof(3*a));

     L1 := 16, 18446744080214109662, 18446744073709551621

kernelopts(dagtag= L1[1]);

     SUM

Note that a product of variables, or a single variable to a numeric power, is a PRODUCT. It is the presence of a numeric coefficient that turns it into a SUM.

Your simplification is only valid if you assume that the parameters such as theta are real. The command evalc makes those assumptions.

simplify(evalc(Re(A)));

It looks (vaguely) like your data is stored as row Vectors. The following procedure takes as input two Vectors (row or column), Array slices, or lists (of the same length, of course) and a boolean-valued filter procedure which when passed a point (x,y) returns true iff the point should be included. It returns the filtered output as column Vectors.

Select:= proc(f, A::~Vector[column], B::~Vector[column])
local M:= convert(select(f@op, convert(<A|B>, listlist)), Matrix);
     M[..,1], M[..,2]
end proc:


Example of use: Suppose that we want to select those points whose first coordinate is even.

A:= <1|2|3|4|5>;  B:= <6|7|8|9|10>;

     A:= [1 2 3 4 5]
     B:= [6 7 8 9 10]

f:= (x,y)-> x::even:
(AA,BB):= Select(f, A, B):
% ^~ %T;

                                        [2 4], [7 9]

Download Select.mw

 

In Maple, a line break has the same syntactic significance as a space; unlike Matlab, the end of line is not considered a statement terminator. So, just find a place where you could put a space and continue on the next line. Preferably, the continuation lines will be indented farther to the right than the statement's initial line. If you are having trouble finding a place to put a space, you should probably rethink your code, and if you post it, I'll help with that.

In the case of a very long constant, string, or name---where you can't use an extra space---you can end a line with backslash \ and continue at the beginning of the next line. I consider this sloppy coding, and in 16 years of Maple usage, I've never had to use it.

It's trivial:

solve({f[k] $ k= 1..n}, {x||(1..n)}):
a||(1..n):= eval([x||(1..n)], %[1])[]:
a||(1..n);

Yes: Use eliminate instead of solve. Your situation is precisely what it's for.

 

First 278 279 280 281 282 283 284 Last Page 280 of 395