Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

You probably don't have the file extension associated with Maple. What is the file extension? Right click on the file to bring up the context menu, then select Properties. On the General tab, look for the line "Opens with:" If it doesn't say Maple or show the maple leaf icon, then click on Change to change the file extension association.

The same steps can be used to make any file extension open with any program; this isn't something specific to Maple.

The command parse can only be applied to one statement at a time, hence the warning message about extra characters. Your string contains four statements, so it'll require multiple calls to parse. By using the options offset and lastread, we can get it to somewhat automatically divide the string into statements.

s:= "restart:\na:=5:\nb:=3:\nP:=28*10^(-3):":
n:= 0:   L:= length(s):
while n < L do parse(s, offset= n, lastread= 'n', statement) end do;

This will generate a warning message regarding the restart and execute the other three statements. There's no meaningful way to parse a restart.

I made one module with almost every feature discussed in this thread, any many new ones:

  • Computations can be done in an arbitrary number of dimensions.
  • Animations can be done in two or three dimensions.
  • It can produce a traditional animation, or, with Explore, an unlimited animation.
  • Plot options can be passed in.
  • The fractions of the friend and enemy arrays to be re-randomized can be independently adjusted.
  • The probability that the friend and enemy arrays will be re-randomized can be adjusted.
  • The sizes of the step toward the origin, the step toward the friend, and the step away from the enemy can be independently adjusted.
  • There are extensive comments.
  • All parameters can be adjusted "on the fly" in the Explore.
  • A frame delay can be set in Explore.

The only thing that I couldn't implement was Acer's idea of inplace modification of the plot structures. Nonetheless, it's plenty fast without this feature.

Here's an example of an animation with four computational dimensions and three display dimensions:

Starlings(1000, 20, .1, .1, .1, dims= [3,4], frames= 600, steps= [.005, .02, .01]);

And here's a link to the worksheet, which also has the Explore:

Starlings.mw

I highly recommend experimenting with adjusting the three step sizes.

 

On the vast majority of websites where one establishes an "account", the account is identified with an email address, and so there can be only one account per email address. Since it's usually easy to generate new email addresses, that's not usually a problem.

Each parse statement reads only one statement from the string. Those statements are "a := 4;",
" a^2;", and " a^3;". Naturally, the output of those statements is 4, 16, and 64.

After each parse statement, the value of n is set to the character position of the first character after the semicolon of the statement that was just read from the string. In this case, those values of n are 8, 13, and 17.

First, please always use the axes names with the line command and other geometry commands that have that option:

line(OT, [Op,T], [x,y]);
line(OU, [Op,U], [x,y]);
line(OV, [Op,V],
[x,y]);

Running your code without these, I had to kill my entire Maple session (not just one worksheet) from Windows Task Manager.

Addressing your Question: For reasons that I don't know, assumptions that a variable is not equal to a particular value rarely work. But if you assume that they're all greater than 0, then you'll get the generic answer that you want.

assume((p[1], p[2], p[3], q[1], q[2], q[3]) >~ 0);

Additionally, your indexed subscripts are not causing any problem here, but, in general, it's safer to use double-underscore subscripts:

assume((p__1, p__2, p__3, q__1, q__2, q__3) >~ 0);

Assuming that they're all global variables, that can be abbreviated to

assume(``||(p,q)||__||(1..3) >~ 0;);

Here's a one-liner procedure for it:

calcView:= (P::seq(specfunc({PLOT, PLOT3D})))-> indets(plots:-display([P]), specfunc(VIEW))[]:

Usage:

calcView(P, P2);

     VIEW(-2 .. 10, -20 .. 20)

By the way, there's no need to end lines with a backslash. It just makes your code look ugly.

There's nothing special about KelvinBei here. If you were to attempt this with any function, you would get the same error message. You're essentially trying to put a number as the second argument to diff, which is neither allowed nor makes sense.

If you want to differentiate and then substitute numeric values, it's easier to use D than diff. What you want in this case can be achieved by

evalf(map[2](D[2](KelvinBei), 0, [seq(1e-3..2, 1e-3)]));

Explanation: The 2 in map[2] indicates iteration with respect to the second functional position. The 2 in D[2] indicates differentiation with respect to the second functional position. The 0 is the first argument to KelvinBei.

Update:

The map[2] can be abbreviated to map2, but I left it as map[2] to emphasize the parallelism with D[2]---in both cases, the 2 refers to the second functional position.

Here's another way, closer to your original. The key thing is to define f with unapply rather than with ->. That abstracts the x so that a number can be substituted for it.

A:= seq(1e-3..2, 1e-3):
f:= unapply(diff(KelvinBei(0,x),x), x):
B:= evalf(map(f, [A])):

 

Your error has nothing to do with the Grid package. Observe:

A:= convert([1,2,3,4], Matrix):
A[1];

     Vector[row](4, [1, 2, 3, 4])

A[2];

Error, Matrix index out of range

A[1,2];

     2

So you see that it's not really appropriate to convert a 1D list into a Matrix. If you want to convert it, then convert it to a Vector. In Maple, a Matrix with one row or column is not quite the same thing as a Vector.

 

When you save a worksheet or document, it's "What you see is what you get." In other words, it's only the appearance of the document that is saved, not any of the variables. If you do want to save variables, the command save will save specific variables, and the command read will restore them.

It still exists in Maple 2016.

Some assumptions help the integration. The following works for me in Maple 2016:

J:= Int(I*sqrt((R*exp(I*theta)+1)/(R*exp(I*theta)+a)), theta= 0..Pi):
value(J) assuming R>0, a>0;

The symbolic solution contains a RootOf of a transcendental function. Such functions have branch cuts (see linked Wikipedia article). It is very difficult to stay continuously on one branch when working numerically (as when plotting) with the RootOf form.

ODE:= diff(y(x),x)*(ln(y(x))+x) = 1:
dsolve({ODE, y(1)=1}, y(x));

y(x) = exp(RootOf(exp(exp(_Z))*Ei(1, exp(_Z))*exp(1)- exp(1)*Ei(1, 1)*exp(exp(_Z))+_Z*exp(1)+exp(1)*x-exp(exp(_Z))))

To get an easier-to-plot symbolic solution, use implicit option to dsolve and plots:-implicitplot.

sol:= dsolve({ODE, y(1)=1}, y(x), implicit);

sol := x+ln(y(x))+Ei(1, y(x))*exp(y(x))+exp(y(x))*(-1-exp(1)*Ei(1, 1))/exp(1) = 0

Notice that the solution contains no RootOf and isn't solved for y(x).

plots:-implicitplot(sol, x= .7..2, y= -1..2, gridrefine= 2);

You can see that both parts of your original plot are contained in the two branches (upper and lower) of this plot. To get the lower branch from a numeric dsolve, use as an initial condition any point on the lower branch.

Here's my modification of vv's code with the smoother transitions of the friend and enemy arrays. This seems much more like the original Mathematica animation.

Starlings:= module()
uses LA= LinearAlgebra;
local
     F, E, n, ndelta,  

     FE:= proc()
     local R:= ['LA:-RandomVector(ndelta, generator= 1..n, datatype= integer[4])' $ 4];
          F[[entries(R[1], nolist)]]:= R[2];
          E[[entries(R[3], nolist)]]:= R[4]
     end proc,
     
     step:= proc(
          x::Vector(datatype=float[8]), y::Vector(datatype=float[8]),
          E::Vector(datatype=integer[4]), F::Vector(datatype=integer[4]),
          mu::integer[4]
     )
     option autocompile;
     local
          i::integer[4],
          ex::float[8], ey::float[8], ed::float[8],
          fx::float[8], fy::float[8], fd::float[8]
     ;
          to mu do
               for i to n do
                    ex:= x[E[i]]-x[i]; ey:= y[E[i]]-y[i]; ed:= sqrt(ex^2+ey^2);
                    fx:= x[F[i]]-x[i]; fy:= y[F[i]]-y[i]; fd:= sqrt(fx^2+fy^2);
                    x[i]:= 0.995*x[i] - 0.01*ex/(ed+0.01) + 0.02*fx/(fd+0.01);
                    y[i]:= 0.995*y[i] - 0.01*ey/(ed+0.01) + 0.02*fy/(fd+0.01)
               od
          od
     end proc,

     ModuleApply:= proc(
          n::posint:= 1000,  #number of points
          num::posint:= 600, #number of frames
          mu::posint:= 10,   #number of iterations between frames
          #fraction of friend and enemy arrays to re-randomize
          delta::And(float, satisfies(x-> 0 <= x and x <= 1)):= 1/mu,
          #probability of changing friend and enemy arrays after a frame
          nu::And(float, satisfies(x-> 0 <= x and x <= 1)):= 1/mu
     )
     local k, x, y, p:= Vector(num), Rand:= rand(0..1.);    
          thismodule:-n:= n;
          ndelta:= round(delta*n);
          (x,y):= 'LA:-RandomVector(n, generator= -1.0..1.0, datatype= float[8])' $ 2;
          (F,E):= 'LA:-RandomVector(n, generator= 1..n, datatype= integer[4])' $ 2;
          for k to num do
               p[k]:= plot(x,y);
               step(x,y,E,F,mu);
               if Rand() < nu then FE() fi
          od;
          plots:-display(
               [entries(p, nolist, indexorder)],
               style=point, symbol= point, symbolsize= 1, axes= none, insequence
          )
     end proc
;
end module:

Starlings(1000, 600, 10, .1, .1);

 

Maple is wrong. Apparently Maple doesn't recognize r = 2^(1/4)*exp(3*Pi*I/8) as a root of the denominator. This r can be simplified to r1 = sqrt(-1+I) (by a long series of simplification steps that I hope to detail in a followup). Then

residue(z^2/(z^4 + 2*z^2 + 2)^2, z= r1);

will give the same result as Mathematica.

First 222 223 224 225 226 227 228 Last Page 224 of 395