John Fredsted

2238 Reputation

15 Badges

20 years, 165 days

MaplePrimes Activity


These are replies submitted by John Fredsted

There seems to be a problem with your interesting proposal:
A := Array(1..2,1..3,1..4,(i,j,k)->i*j-k^2);
B := Array(rtable_dims(A),(i,j,k)->A[i,k,j]);
Error, Array index out of range
Matrices have two dimensions, i.e., two indices uniquely identifies a given entry. Arrays, on the hand, may be multi-dimensional, i.e., having more than two dimensions (note that Arrays may also have one or two dimensions, so you can say that an Array is a generalization of a Matrix). An example is the following:
A := Array(1..2,1..3,1..4,(i,j,k)->i*j-k^2);
where examples of entries are
A[1,2,3];   # Equals 1*2-3^2
A[2,1,4];   # Equals 2*1-4^2
                               -7
                              -14
I didn't know about the allvalues(...) method; now finally I can resolve those annoying RootOf(...) expressions.
I didn't know about the allvalues(...) method; now finally I can resolve those annoying RootOf(...) expressions.
Yesterday I experienced the same thing with one of my blog entries. Concerning the role of the moderator, I reached the same conclusion as you do. It is comforting to read that it isn't only me that have the annoying (for why couldn't they have been discovered prior to posting) habit of making minor corrections after posting. Therefore, I think a "Drafts folder" might be of some use; there a potential blog entry might be put for a short while in which the corrections might pop up in ones mind.
Very nice, I didn't know that ":-" could "flab in the breeze" like that.
Now I begin to see where you want to go (it is almost twenty years ago I learned above Lagrange multipliers, so I've just had to consult my old book on linear algebra about the subject). You seem to be missing the differentiation with respect to the third variable, z. I've rewritten you code as follows:
f := x*y*z:
q := x^2+2*y^2+3*z^2-6:
g := f+mu*q:
diff_x := diff(g,x):
diff_y := diff(g,y):
diff_z := diff(g,z):
sols := solve({q = 0,diff_x = 0,diff_y = 0,diff_z = 0},{x,y,z,mu}):
There seems to be five different solutions (maybe I'm mistaken), which may be accessed as follows (with $'s and the like in your case, of course):
sols[1];
sols[2];
sols[3];
sols[4];
sols[5];
For instance taking the first,
sols[1];
{mu = 0, z = 0, x = RootOf(_Z^2-6), y = 0}
the values may be retrieved as follows:
rhs(sols[1][1]);   # mu
rhs(sols[1][2]);   # z
rhs(sols[1][3]);   # x
rhs(sols[1][4]);   # y
You have a point; maybe it's asking for problems using protected names like "array" as a parameter in the procedure. Even though it evidently works (actually, why does it?), maybe in the future I should refrain from doing so.
I've translated your lines to Maple code:
f := x*y*z:
q := x^2+2*y^2+3*z^2-6:
g := f+mu*q:
exp1 := diff(g,x):
exp2 := diff(g,y):
exp3 := solve({q,exp1,exp2},{x,y,mu}):
ans1 := subs({x = 1,y = 2},f);
ans2 := subs({x = 2,y = 3},f);

                          ans1 := 2 z
                          ans2 := 6 z
In doing so, I noticed some typos in your code: 1. Missing * between x, y, and z for f, as well as elsewhere (I don't know whether they are mandatory or not in Maple TA). 2. In the expressions for ans1 and ans2, (...) and {...} are nested wrongly. 3. In the expression for exp3, you use [...] brackets around x, y, and mu. I think you have to use {...} brackets, as indicated. As you can see, for x and y in the "subs" lines I've chosen some numbers at random. I hope that was of some help.
The reason why my former answer was quite general is that I'm having difficulties understanding your code: First, the syntax, using $'s for instance, is unknown to me. A $ sign in front of variables is used for instance in the web programming language PHP, but not in Maple (as far as I know). Second, I'm unable to disentangle your code; could you break it down, or explain to me the purpose or the origin of it?
Of course you are right if nargs = 1 is impossible (as it is, see PS). What surprised me the first time I read about indexing functions was that a function with three explicitly declared parameters could accept just two. Usually, Maple raises an error when a function is supplied with too few parameters. I suppose that was the reason why I coded it the way I did. PS: I've just looked up the help page on indexing functions and there it explicitly says that the procedure `index/method` is invoked with either two or three parameters. So, in the future I'll code it the way you suggest.
As far as I'm aware, my method using `index/makeIndex` does not use any arrays, it only uses Arrays and sets.
It's getting a little late here in Denmark, at least for me, so I'll be logging off. I suppose the sun is still shining on you guys. But I'll be back tomorrow to see if somehow has "tamed" rtable_elems(...).
Even though I did not look up the help page on "rtable_elems", that was what I suspected to be the cause of the missing elements.
Selecting for "algebraic" instead of "posint" (to get something more interesting) it seems to work:
map([lhs],select(
	t -> type(rhs(t),algebraic),
	rtable_elems(christoffel:-getComps())
));

{
[3, 3, 2], [4, 2, 4], [2, 3, 3], [1, 1, 2], [4, 3, 4],
[1, 2, 1], [3, 4, 4], [4, 4, 2], [2, 4, 4], [4, 4, 3],
[2, 1, 1], [3, 2, 3], [2, 2, 2]
}
Or does it? Why do only the nonzero components figure here, when type(0,algebraic) = true? Shouldn't all 64 possible index-triples figure here, as they do using my method:
isAlgebraic := x -> if type(rhs(x),algebraic) then lhs(x) end if:
A := christoffel:-getComps():
B := Array(makeIndex,A):
S := convert(map(isAlgebraic,B),set);

S := {
[4, 1, 3], [4, 1, 4], [4, 2, 1], [4, 2, 2], [4, 2, 3],
[4, 3, 1], [4, 3, 2], [4, 3, 3], [4, 4, 1], [1, 1, 2],
[3, 4, 1], [1, 2, 2], [1, 2, 3], [1, 2, 4], [1, 3, 1],
[1, 3, 2], [1, 3, 3], [1, 3, 4], [1, 4, 1], [1, 4, 2],
[1, 4, 3], [1, 4, 4], [2, 1, 2], [2, 1, 3], [2, 1, 4],
[2, 2, 1], [2, 4, 3], [2, 3, 4], [2, 3, 1], [4, 4, 4],
[2, 1, 1], [1, 2, 1], [2, 2, 2], [2, 3, 3], [3, 3, 2],
[2, 4, 4], [4, 4, 2], [3, 3, 3], [3, 2, 3], [3, 3, 4],
[3, 4, 4], [4, 4, 3], [4, 2, 4], [4, 3, 4], [2, 2, 3],
[2, 2, 4], [2, 3, 2], [2, 4, 1], [2, 4, 2], [3, 1, 1],
[3, 1, 2], [3, 1, 3], [3, 1, 4], [3, 2, 1], [3, 2, 2],
[3, 2, 4], [3, 3, 1], [3, 4, 2], [3, 4, 3], [4, 1, 1],
[4, 1, 2], [1, 1, 1], [1, 1, 3], [1, 1, 4]
}
First 64 65 66 67 68 Page 66 of 68