John Fredsted

2238 Reputation

15 Badges

20 years, 163 days

MaplePrimes Activity


These are answers submitted by John Fredsted

You can write as follows (note that your square brackets have been replaced by parentheses, even though not needed here, because square brackets denote a list):

(4*a^2 - 3*a*b + 2*b^2) + ((2*a^2 - 4*b^2) - a*b);

Maple simplifies it to 6*a^2-4*a*b-2*b^2. If Maple does not by itself simplify an expression, then you can use simplify, as in the following example:

simplify(cos(x)^2 + sin(x)^2);

It does the very same thing as end if, being just the reverse order of the letters making up if. Like od is the reverse of do in a for or a while loop.

But I think the use of fi (and od) has been deprecated, i.e., it is recommended to use end if (and end do) instead.

I would do something like the following (with appropiate acknowledgment to what Joe Riel has done above):

assume(a::positive):
hyperbola := (x + c^2/a)^2 - (c*t)^2 = c^4/a^2:
particle(t) := solve(hyperbola,t)[1];
asymptote(t) := convert(asympt(particle(t),x,1),'polynom');
photon(t) := x/c + t0;

From the output it is obvious that the answer to the question is t0 = c/a.

I am not quite sure what you have in mind, but it seems to me that you are working with quadratic forms. If that is correct, then maybe the following example is helpful:

Define some quadratic form Q by:

x := Vector(3,i -> x||i);
A := Matrix(3,3,(i,j) -> a||i||j,shape = symmetric);
Q := LinearAlgebra:-Transpose(x) . A . x;

Up to a factor of 2, extract the matrix A by calculating the Hessian as:

Hessian := Matrix(3,3,(i,j) -> diff(Q,x[i],x[j]));

I see what you mean: the fonts of the captions of the following two plots certainly do not look the same even though they ought to, I would say:

with(plots):
plot(x^2,x = -1..1,
   caption = ["f(x)",font = [verdana,bold,10]]
);
plot3d(x^2 + y^2,x = -1..1,y = -1..1,
   caption = ["f(x,y)",font = [verdana,bold,10]]
);

The font of the 3d plot caption seems ok, but the font of the 2d plot caption certainly does not; it does not seem to be verdana.

I was pleasantly surprised to read that you have downloaded my Gravitation package. It is, of course, always nice to see that someone else finds one work (potentially) interesting.

The description given by Joe and Georgios should be sufficient. Anyway, I can relate to your situation: some years ago I struggled to figure out the very same. Back then I had trouble finding documentation on how to do it, primarily, I guess, because I did not know what to look for: if you cannot formulate the question, you cannot find an answer. Maybe the help page ?repository,management could be useful to you.

A comment on the package: Even though the package is not even one year old, today I would write it quite differently:

  • I would replace most, if not all, of the for loops with Array constructors.
  • I would throw out the procedures setIndexTranspose and setIndexPermute, using instead (also here) Array constructors, not because the procedures are incorrect, but because the use of constructors is clearly superior, compare my blog entry Tip: Transpose a pair of indices of an Array.

The fact that these potential improvements are now obvious to me is a testimony to the significance of attending this forum: over a relatively short period of time I have learned from other guys at this forum some very nice tricks for making code faster and more compact. Thanks!

Using the formula given at

http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html

for the distance between a point and a line in 3D, I have tried the following, where p1 and p2 are considered to be two points on the symmetry axis of the cylinder, and r to be the radius of the cylinder:

with(LinearAlgebra):
with(Optimization):
cylinderDist := (p0,p1,p2,r) -> abs(
	VectorNorm(CrossProduct(p2 - p1,p1 - p0),2,conjugate = false) /
	VectorNorm(p2 - p1,2,conjugate = false)
	- r
):
sumSquareError := (p1,p2,r) -> add(
	cylinderDist(Vector([seq](data[i,j],j = 1..3)),p1,p2,r)^2
,i = 1..RowDimension(data)):
Minimize(
	sumSquareError(Vector([a1,b1,c1]),Vector([a2,b2,c2]),r)
	,{(a1 - a2)^2 + (b1 - b2)^2 + (c1 - c2)^2 = 1}
#	,feasibilitytolerance = 10.,optimalitytolerance = 10.
);

Unfortunately, the following error results:

Error, (in Optimization:-NLPSolve) no improved point could be found; consider increasing optimality tolerance and checking correctness of objective and nonlinear constraint functions

Hopefully, someone with real experience in optimization can help us out.

Try the following:

plot([seq([i,sin(i)],i = 1..12)]);

PS: It does use seq, which you seem to exclude, but it is shorter and faster than your for-loop construction.

You can insert text using, for instance, Insert -> Section, Insert -> Subsection, or Insert -> Text.

Maybe you can use the environment variable Order, see the help page ?Order.

I suppose that a * b means the cross product of the vectors a and b, something I would write as a x b. Use DotProduct (as before, but now on two different vectors, which is really what it is meant for), and CrossProduct as follows:

A := Vector([a1,a2,a3]):
B := Vector([b1,b2,b3]):
LinearAlgebra:-DotProduct(A,B,conjugate = false);
LinearAlgebra:-CrossProduct(A,B);

You may also write the cross product as

with(LinearAlgebra):
A &x B;

You can use either VectorNorm or DotProduct as follows:

V := Vector([a,b,c]);
LinearAlgebra:-VectorNorm(V,2,conjugate = false);
sqrt(LinearAlgebra:-DotProduct(V,V,conjugate = false));

You could also write sprintf("file%d.txt",1), etc.

To plot the four different derivatives in the same plot you can use display as follows:

with(plots):
p(x) := 2*x^5-5*x^4+3*x^3-3*x^2+x+2:
plot1 := plot(diff(p(x),x$1),x = -10..10):
plot2 := plot(diff(p(x),x$2),x = -10..10):
plot3 := plot(diff(p(x),x$3),x = -10..10):
plot4 := plot(diff(p(x),x$4),x = -10..10):
display([plot1,plot2,plot3,plot4]);

Or, equivalently and shorter:

with(plots):
display([seq](plot(diff(p(x),x$i),x = -10..10),i = 1..4));

I am not quite sure what you are asking for, but if you want to select specific lists of lists in a set (being part of the definition of some permutation group), you can use select as follows: Let s_6 be your permutation group, and define the procedure

selectCycles := proc(cycleType::list(posint),cycles::set(list(list)))
	select(type,cycles,map(n -> [posint$n],cycleType))
end proc:

which selects from all cycles the cycles of type cycleType. Because the set of lists of lists in the definition of s_6 can be accessed as op(2,s_6), specific cycle types of s_6 can be pulled out as follows:

cycles := op(2,s_6):
selectCycles([2],cycles);
selectCycles([3],cycles);
selectCycles([4],cycles);
selectCycles([5],cycles);
selectCycles([6],cycles);
selectCycles([2,2],cycles);
selectCycles([3,2],cycles);
selectCycles([4,2],cycles);
selectCycles([3,3],cycles);
                           {[[1, 2]]}
                         {[[1, 2, 3]]}
                        {[[1, 2, 3, 4]]}
                      {[[1, 2, 3, 4, 5]]}
                     {[[1, 2, 3, 4, 5, 6]]}
                       {[[1, 2], [3, 4]]}
                     {[[1, 2, 3], [4, 5]]}
                    {[[1, 2, 3, 4], [5, 6]]}
                    {[[1, 2, 3], [4, 5, 6]]}

PS: Quite conceivably, using group methods of some kind, there exist some smarter method to extract the appropiate cycles, but being no expert in group theory I am unable to come up with any such.

First 11 12 13 14 15 16 17 Page 13 of 19