acer

20475 Reputation

29 Badges

15 years, 26 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@mmcdara I may well not understand properly what kind of characters you want, and where, but perhaps this will give you some ideas. 

I wasn't sure if you wanted to replace the symbol "ID" used at a vertex, or place something at that level, etc.

Note that plots:-textplot allows the supposed text to be supplied as typeset(some_seq) where some_seq can be an expression sequence containing "\n" entries. And you can use entities in the other entries of such a sequence to be typeset.

NAC_ac.mw

@mmcdara I'm curious about your need that made you turn to image drawing facilities to modify/construct your rendered graphs (in the Graph theory sense).

The results from DrawGraph look much better than they used to. But I'd agree that there is room for improvement.

One way to get typeset Greek letters or other entities on the vertices of a drawn Graph is by using normal alphabetic characters in the Graph passed to DrawGraph and then substitution into the resulting PLOT structure. Eg, using a variety of ways (HTML entities, straight Greel letter name, unicode),

restart;

plots:-setoptions(gridlines=false):

with(GraphTheory):

P := DrawGraph(Graph(directed,{["a","b"],["cc","b"],
                               ["cc","a"],["cc","d"]})):

subs(["a"=Psi,
      "b"=`Ψ`,
      "cc"=`#mrow(mo("Ψ"),mo("↑"))`,
      "d"=`#mo(↑)`],
     P);

 

Download graph_entity1.mw

Or did your goal also include a customized look for the arrows designating a directed Graph, eg. something like this where the edge is depicted with a stretched arrow entity?

I understand, if you've already got a working mechanism for doing any or all of that via drawing and images. I was just curious about the main obstacles you faced.

@mmcdara I do not always mention it when I submit a bug report against an issue I find while investigating a Question in this forum.

I mentioned here to convey also that I considered this example a weakness in simplify, since the Question and my Answer were more about how to apply commands to each entry of the Matrix. (The OP seemed to have already found an adequate command, but wanted to apply it throughout, I believe.)

I considered the example something that simplify might reasonably be expected to handle itself (ie. the trig arguments are not large integers, and expand doesn't blow the individual trig calls up to huge expressions.)

Bug reports generally help.

The simplify command is being improved in at least some ways. Consider this basic example, which produces zero in Maple 2019,

restart;
ff := cosh(z) + sinh(z):
simplify( exp(z) - ff );
                          0

@michalkvasnicka On what grounds do you make this strong claim?

Could you give your example?

Additional details that might be relevant include: Maple version, Operating system, Maple language pack (if any).

In case anyone's interested, I'm submitting a bug report about this weakness in simplify ,

restart;

ee := cos(omega*t + alpha)/2
      - cos(omega*t + alpha + Pi/3)/2
      - sin(omega*t + alpha + Pi/6)/2:

expand(ee);
                               0

lprint( simplify(ee) );
  1/2*cos(omega*t+alpha)-1/2*cos(omega*t+alpha+1/3*Pi)-1/2*sin(omega*t+alpha+1/6*Pi)

lprint( simplify(ee, trig) );
  1/2*cos(omega*t+alpha)-1/2*cos(omega*t+alpha+1/3*Pi)-1/2*sin(omega*t+alpha+1/6*Pi)

@nm The scenario you describe -- with nested calls to commands without proper regard for what they might return and a reasonable chance of a mistaken call -- sounds to me like inadequate type checking, parameter checking, and quality of programming on the user's part.

@tomleslie I agree with you, Tom.

This member's habit of posting only images is very rude and unhelpful behavior.

Why are you using squiggly brackets {...} ? Those are for creating sets.

Your code attempts to add/subtract sets, which does not make sense.

Use round brackets as delimiters.

@mmcdara It's not difficult to roll your own code that constructs the XML for the running sequence of GUI Tables to embed.

The following was done in Maple 2015.2.

It would be nice is DocumentTools:-Tabulate offered an option to treat mxn or mxnx3 float[8] Arrays as images. Then you could use the Tab2 approach directly. I'll submit a Software Change Request.

restart;

F := proc()
  local blankblock,i, im, p, S, xml;
  uses DocumentTools, DocumentTools:-Layout;

  for i from 1 to 4 do

    # delay for demo purpose only
    if i<>1 then Threads:-Sleep(1.5); end if;

    # p is some plot, and im is some image
    # This is just a toy example, p and im don't have
    # any special meaning.
    #
    S := Statistics:-Sample(Uniform(0,1),[1..50,1..3,1..3]);
    p := plots:-pointplot(S[..,1..2,1], size=[300,300],
                          symbolsize=15, symbol=solidcircle);
    im := Array(S,datatype=float[8]);

    xml[i] := Table(Column(weight=40),Column(weight=20),
                    Column(weight=40),
                    interior=none,alignment=center,
                    widthmode=pixels,width=500,
                    Row(align=center,
                        Cell(InlinePlot(p)),
                        Cell(sprintf("Iteration %a of 4",i)),
                        Cell(Image(im,height=270,width=270))));

    blankblock := DocumentBlock(Group(Input(Textfield("\n"))));
    InsertContent(Worksheet(seq(op([xml[j],
                                    blankblock]),j=1..i)));

  end do;

  return NULL;

end proc:

 

F();

 

Download Tab3.mw

@Carl Love I too prefer eval over assign.

Partly that's because -- much more often than not -- I find it convenient to not have any scalar  numeric values assigned to the names involved with formulas. 

Having mixed expressions with floats and symbols often makes manipulation (factoring, simplification, integration, etc) problematic. I see so many worksheets where people have problems because they introduced numeric values to parameter names far too early.

 

@Carl Love The OP's original was done in Maple 12.

Here is your code executed in Maple 12.02 (with map replacing elementwise ~, and time replacing CodeTools:-Usage).

I also added the fsolve approach from my Answer. (I've deliberately used option discont for plotting all five, and deliberately kept the default adaptive option since some of the curves get steep. So the plotting options are the same.)

In Maple 12 the indexed RootOf approach takes about 19 seconds to compute the plot while the fsolve approach takes about 5.5 seconds.

In my Maple 2019.0  the indexed RootOf approach takes about 120 seconds to compute the plot while the fsolve approach takes about 7 seconds.

That's all done using 64bit Linux.

I will try and dig into why `evalf/RootOf` has slowed down between Maple 12 and Maple 2019.

But I don't see why the OP would want to use the indexed RootOfs rather than fsolve for plotting the roots of a univariate polynomial, even in Maple 12.02 for this degree 5 example.

restart:

kernelopts(version);

`Maple 12.02, X86 64 LINUX, Dec 10 2008 Build ID 377066`

gm := V -> 1/sqrt(1-V^2):
T := (1/sqrt(1-V^2))*(w-k*V):
S := (1/sqrt(1-V^2))*(w*V-k):

f := -135/4*T^5+369/16*T^3*S^2+47/4*I*T^4-93/16*I*T^2*S^2+T^3-2/3*T^3*S*B-27/16*S^4*T+3/16*I*S^4-1/3*T*S^2+2/9*S^3*T*B:

Hgen:= simplify(rationalize(f)):

I don't think that setting _EnvExplicit to true can possibly do anything beneficial for a polynomial of this complexity. While I also don't think that it can cause harm, since there's no reason to set it, I'd rather not risk it. So, the next line is commented out.

(* _EnvExplicit := true; *)

H:=[solve(numer(Hgen),w)]
:

If the solve goes as planned, then H will be a list with a single entry, a RootOf expression.

nops(H), type(H, list(RootOf));

1, true

So, H is indeed of the the form that I hoped.

 

The part of  this worksheet that solves your issue of the slowness of allvalues is in the next line. The key point is that numeric values are supplied for B and V before the expression is passed to allvalues.

st := time():
Hav:= [allvalues(eval(H[], [B= 1, V= 0.8]))]:
(time()-st)*`seconds`;

.984*seconds

nops(Hav), type(Hav, list(RootOf));

5, true

There's no need for you to re-enter all those plot options. Your entire plot can be done as below.

st:=time():
P:=plot(
   map(Im,Hav), k= 0..1, discont,
   color= [red, black, green, blue, yellow],
   linestyle= solid, thickness= 2,
   axesfont = ["TimesNewRoman", 18],
   labelfont = ["TimesNewRoman", 22], labels = [conjugate(k), Im(conjugate(omega))],
   axes = "boxed",
   gridlines= false
):
time()-st;
P;
   

18.963

restart:

gm := V -> 1/sqrt(1-V^2):
T := (1/sqrt(1-V^2))*(w-k*V):
S := (1/sqrt(1-V^2))*(w*V-k):

f := -135/4*T^5+369/16*T^3*S^2+47/4*I*T^4-93/16*I*T^2*S^2+T^3-2/3*T^3*S*B-27/16*S^4*T+3/16*I*S^4-1/3*T*S^2+2/9*S^3*T*B:

Hgen:= simplify(rationalize(f)):

HHp := proc(kk) option remember, system;
         local res;
         res := fsolve(eval(numer(Hgen),[B=1,V=0.8,k=kk]),w);
       end proc:

st := time():
opts := thickness=2, symbol=solidcircle, symbolsize=12:
forget(HHp);
pplt1 := plot(k->Im(HHp(k)[1]), 0..1, color=yellow, discont=true, opts):
pplt2 := plot(k->Im(HHp(k)[2]), 0..1, color=blue, discont=true, opts):
pplt3 := plot(k->Im(HHp(k)[3]), 0..1, color=black, discont=true, opts):
pplt4 := plot(k->Im(HHp(k)[4]), 0..1, color=green, discont=true, opts):
pplt5 := plot(k->Im(HHp(k)[5]), 0..1, color=red, discont=true, opts):
P := plots:-display(pplt5, pplt4, pplt3, pplt2, pplt1, gridlines = false,
                    axesfont = ["TimesNewRoman", 18],
                    labelfont = ["TimesNewRoman", 22],
                    labels = [conjugate(k), Im(conjugate(omega))]):
(time()-st)*`seconds`;
P;

5.311*seconds

 

ImagRootPlot_fsolve_Maple12.02.mw

ImagRootPlot_fsolve_Maple2019.0.mw

 

I don't understand why anyone would choose the relatively inefficient indexed RootOf approach here.

restart;
with(plots):

gm := V -> 1/sqrt(1-V^2):
T := (1/sqrt(1-V^2))*(w-k*V):
S := (1/sqrt(1-V^2))*(w*V-k):

f := unapply(-135/4*T^5+369/16*T^3*S^2+47/4*I*T^4-93/16*I*T^2*S^2+T^3-2/3*T^3*S*B-27/16*S^4*T+3/16*I*S^4-1/3*T*S^2+2/9*S^3*T*B,w,V,k):

Hgen := simplify(simplify(expand(rationalize(f(w, V, k)))), size)

(1/144)*(-4860*(-w+k*V)*((k^4+(4/135-(41/60)*w^2)*k^2+(1/20)*w^4-(4/405)*w^2)*V^4-(79/30)*k*(k^2-(35/79)*w^2+32/2133)*w*V^3+(-(41/60)*k^4+(-16/405+(107/30)*w^2)*k^2-(41/60)*w^4+(16/405)*w^2)*V^2+(7/6)*k*(k^2-(79/35)*w^2+32/945)*w*V+(1/20)*k^4+(4/405-(41/60)*w^2)*k^2+w^4-(4/135)*w^2)*(1-V^2)^(1/2)+1692*(V-1)*(V+1)*((-((93/188)*I)*w^2*k^2+((3/188)*I)*w^4-(8/423)*B*w^3*k+(8/141)*B*k^3*w+I*k^4)*V^4+(-(8/141)*B*k^4+(8/423)*B*w^4-(16/141)*B*w^2*k^2+((87/94)*I)*w^3*k-((283/94)*I)*w*k^3)*V^3+(-((93/188)*I)*w^4+(16/141)*B*w^3*k+((387/94)*I)*w^2*k^2-((93/188)*I)*k^4+(16/141)*B*k^3*w)*V^2+(-((283/94)*I)*w^3*k+(8/423)*B*k^4-(8/141)*B*w^4-(16/141)*B*w^2*k^2+((87/94)*I)*w*k^3)*V+((3/188)*I)*k^4-(8/423)*B*k^3*w+I*w^4+(8/141)*B*w^3*k-((93/188)*I)*w^2*k^2))/((V-1)^3*(V+1)^3)

_EnvExplicit := false;

false

HH:=[solve(numer(Hgen),w)]:

H := subsindets(HH,RootOf,u->seq(RootOf(op(1,u),_Z,index=i),i=1..5)):
nops(H);

5

st := time():
plt1 := plot(Im(eval(H[1], [B = 1, V=0.8])), k = 0 .. 1, color = red, linestyle = solid, discont = true, thickness=2, axesfont = ["TimesNewRoman", 18], labelfont = ["TimesNewRoman", 22], labels = [conjugate(k), Im(conjugate(omega))], axes = "boxed"):
plt2 := plot(Im(eval(H[2], [B = 1, V=0.8])), k = 0 .. 1, color = black, linestyle = solid, discont = true, thickness=2, axesfont = ["TimesNewRoman", 18], labelfont = ["TimesNewRoman", 22], labels = [conjugate(k), Im(conjugate(omega))], axes = "boxed"):
plt3 := plot(Im(eval(H[3], [B = 1, V=0.8])), k = 0 .. 1, color = green, linestyle = solid, discont = true, thickness=2, axesfont = ["TimesNewRoman", 18], labelfont = ["TimesNewRoman", 22], labels = [conjugate(k), Im(conjugate(omega))], axes = "boxed"):
plt4 := plot(Im(eval(H[4], [B = 1, V=0.8])), k = 0 .. 1, color = blue, linestyle = solid, discont = true, thickness=2, axesfont = ["TimesNewRoman", 18], labelfont = ["TimesNewRoman", 22], labels = [conjugate(k), Im(conjugate(omega))], axes = "boxed"):
plt5 := plot(Im(eval(H[5], [B = 1, V=0.8])), k = 0 .. 1, color = yellow, linestyle = solid, discont = true, thickness=2, axesfont = ["TimesNewRoman", 18], labelfont = ["TimesNewRoman", 22], labels = [conjugate(k), Im(conjugate(omega))], axes = "boxed"):
(time()-st)*`seconds`;

38.425*seconds

display(plt1, plt2, plt3, plt4, plt5, gridlines = false);

HHp := proc(kk) option remember, system;

         local res;

         res := fsolve(eval(numer(Hgen),[B=1,V=0.8,k=kk]),w);

       end proc:

opts := thickness=2, symbol=solidcircle, symbolsize=12:

forget(HHp);

st := time():

pplt1 := plot(k->Im(HHp(k)[1]), 0..1, color=yellow, discont=true, opts):

pplt2 := plot(k->Im(HHp(k)[2]), 0..1, color=blue, discont=true, opts):

pplt3 := plot(k->Im(HHp(k)[3]), 0..1, color=black, discont=true, opts):

pplt4 := plot(k->Im(HHp(k)[4]), 0..1, color=green, discont=true, opts):

pplt5 := plot(k->Im(HHp(k)[5]), 0..1, color=red, discont=true, opts):

(time()-st)*`seconds`;

10.227*seconds

plots:-display(pplt5, pplt4, pplt3, pplt2, pplt1, gridlines = false,
                    axesfont = ["TimesNewRoman", 18],
                    labelfont = ["TimesNewRoman", 22],
                    labels = [conjugate(k), Im(conjugate(omega))]);

 

Download file3_acc.mw

@tomleslie This works by fortune. That might be fine, since it's quite possible that the OP just needs to give the answer.

But it does not follow that the result is correct to a certain accuracy just because the absolute difference between two iterations (done at increasing working precision) falls below a target tolerance. It happens to produce the right answer for this well behaved example, but in general this approach need not work.

@digerdiga Which version and operating system are you using? 

First 67 68 69 70 71 72 73 Last Page 69 of 438