Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@sand15 There's no need to normalize your random numbers to a 0..1 float scale. The integers generated by naked rand() are good enough, and more efficient.

@Magma In most cases, randomize() should only be used as a top-level command, and it should only be used once (per restart).

Kitonum's code is extremely inefficient. I will try to rewrite it.

@Magma Your results indicate that the output= permutation part isn't working. I'll come up with something else in a few minutes.

@Magma Try this:

RandPerm:= (n::nonnegint)-> sort(['rand()' $ n], 'output'= 'permutation'):
#Example:
RandPerm(9);

      [3, 1, 6, 7, 5, 9, 2, 8, 4]

I'm sure that my rand command will work in Maple 15, but I'm not sure about the output= permutation option to sort. Let me know if that works. If not, I can easily make a workaround.

@Kyle White Your account seems suspicious to me. If you don't say something meaningful about Maple within an hour, I'm flagging as a spammer.

@Carl Love It is very easy to modify the above code so that the curves are plotted in the complex plane parameterized for 0 <= k <= 1. All that's needed are two small changes to the odeplot; however, I made a few other simplifications to the overall code also.

restart:
Digits:= trunc(evalhf(Digits)):
gm:= 1/sqrt(1-V^2):
T:= w-k*V:
S:= w*V-k:
H:= numer(T*S^2*gm^3*3/2+I*S^2(1+I*27/4*T*gm)*gm^2-(1+I*27/4*T*gm)*(1+I*5*T*gm)*T*gm):
Vlist:= [
   Record("V"= 0.8, "color"= "Black", "plot"= ()),
   Record("V"= 0.9, "color"= "Red", "plot"= ()),
   Record("V"= 0.99, "color"= "Blue", "plot"= ())
]:
R:= [solve(H, w, explicit)]:
d:= nops(R): #number of roots
for v in Vlist do
   S:= dsolve(
      {   #odes:
          seq(eval(diff(r[i](k),k) = diff(R[i],k), V= v:-V), i= 1..d),
          #initial conditions:
          ([seq(r[i](0), i= 1..d)] =~ evalf(eval(R, [V= v:-V, k= 0])))[]
      },
      numeric
   );
   v:-plot:= plots:-odeplot(S, [seq([Re,Im](r[i](k)), i= 1..d)], k= 0..1, color= v:-color)
od:   
plots:-display([seq(v:-plot, v= Vlist)], size= [987,610]);

@mmcdara Here's another anomaly related to weights (but not to DataSummary). Compare

Median(X, weights= Y) 

with

Quantile(X, 0.5, weights= Y).

I guess it's somewhat a matter of opinion: Do you feel that those two should be equal? The help ?Quantile does explicitly describe the eight (!) formulas that can be used, but doesn't describe how weights are handled by any of those 8. And, in my opinion, none of the 8 are adequate for the weighted case.

@a_simsim Off the top of my head (someone please correct if I've forgotten some), Maple's only mutable structures are tables, rtables (which includes Vectors, Matrixes, and Arrays), modules (which includes objects and Records), and procedures (which includes arrow expressions such as x->x^2); all other structures, including containers such as sequences, lists, and sets, are immutable.

A benefit of an immutable structure is that only one copy can exist (per kernel) in memory, with all references being pointers to that single copy. Part of the process called automatic simplification is to match nascent structures with those already stored (in a master table called the simplification table) and eliminate duplicates. Thus, checking equality of immutable structures becomes as simple as comparing their addresses, and is thus very quick. All this happens in the background, but being aware of it helps one to write efficient code.

A drawback of an immutable structure is that any change made to it necessitates that the entire structure be recreated, no matter how large it is. So, one of the most-common causes of slow performance is to add elements one at a time to a sequence, list, or set. In almost all such cases, a table or Vector should be used instead.

The benefits and drawbacks of mutable structures are just the reverse of those of immutable structures: Modifying (or adding to) the structure is trivial, but equality comparisons are not, and duplicate copies consume memory.

I get this plot:

It's a circle of radius 5 centered at the orgin bisected by a diameter pitched at angle Pi/9. That seems to be exactly what you specified. So, what's wrong?

@Racine65 Don't be misled that that's giving you the exact value of (1/2)! just because you used the keyword exact. Rather, it's giving you the exact rational value of 0.8862269255, which is the 10-digit decimal approximation of (1/2)!.

The simplest form of the exact value is sqrt(Pi)/2. It's an irrational number, and Maple has many ways to get there starting from (1/2)!. Is that not acceptable to you?

@izhammulya Sure: You can color particular edges or all edges the same color or each edge a different color all with GraphTheory:-HighlightEdges. In the example below, I continue from the code above and color each edge based on its relative length:

Dist:= (v1,v2)-> evalf(norm(<P[v1]-~P[v2]>, 2)): #P is your list of vertex coordinates.
E:= [GT:-Edges(G)[]]: # [...[]] converts set to list
dists:= (Dist@op)~(E): #List of edge lengths.
(maxD,minD):= (max,min)(dists):
GT:-HighlightEdges(G, E, [seq(COLOR(HSV, .85*(d-minD)/(maxD-minD), .85, .85), d= dists)]);
GT:-DrawGraph(G);

A similar treatment can be given to the vertices using GraphTheory:-HighlightVertex.

@muchlove What data should I use for the x-errors? Do you have a separate list of those?

@garth 
 

restart:

#All given info:
ode:= diff(y(t),t) = (3-y(t))*(y(t)+1); #NB: y(t), not just y
(a,b):= (0,5); #interval
ic:= y(a) = 4;
Delta__t:= 1.0;

diff(y(t), t) = (3-y(t))*(y(t)+1)

0, 5

y(0) = 4

1.0

Y__exact:= dsolve({ode, ic});

y(t) = -(exp(-4*t)+15)/(exp(-4*t)-5)

Y__Euler:= dsolve(
   {ode, ic}, numeric, method= classical[foreuler], stepsize= Delta__t,
   output= Array([seq(k, k= a..b, Delta__t)])
);

Vector(2, {(1) = Vector[row](2, {(1) = t, (2) = t}), (2) = Matrix(6, 2, {(1, 1) = 0., (1, 2) = 4., (2, 1) = 1.0, (2, 2) = -1.0, (3, 1) = 2.0, (3, 2) = -1.0, (4, 1) = 3.0, (4, 2) = -1.0, (5, 1) = 4.0, (5, 2) = -1.0, (6, 1) = 5.0, (6, 2) = -1.0})})

Arrows:= DEtools:-dfieldplot(ode, y(t), t= a..b, y= -2..5, color= yellow);

Curves:= plot(
   [eval(y(t), Y__exact), Y__Euler[2,1]], t= a..b,
   style= [line, pointline], linestyle= [solid, dash], legend= [Exact, Euler],
   thickness= [2,1],
   symbolsize= 20
);

plots:-display([Arrows, Curves], gridlines= false);

 


 

Download Euler_fieldplot.mw

This site renders the plots (rather than just using a GIF) and makes a few errors in doing so. The plot actually looks like this:

@radaar Please post your code. I may be able to re-arrange your evalhf so that it works. However, I won't be able to do it if the computation is inherently symbolic. You just need to post the plaintext file that you pass to read; I don't need to see any output.

@radaar You cannot use a restart statement in "a procedure or from a file being read by the read statement." Recalling your other recent Question, I believe that you are using a read statement, on my recommendation.

Regarding evalhf: It often requires some arcane and lengthy syntax to workaround evalhf's severe restrictions, but it is very often worth it. I often get a factor-of-25 speedup from it. 

First 280 281 282 283 284 285 286 Last Page 282 of 709