acer

32333 Reputation

29 Badges

19 years, 323 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@lcz There is some information via,

showstat(GraphTheory::AllPairsDistanceImpl);

But if _EnvDisableExt <> true (ie. default) then that may call AllPairsDistanceExt which is externally compiled and not visible as source.

@Earl In Maple 2020.2 try adding the option factor=true to the implicitplot call.

restart:

kernelopts(version);

`Maple 2020.2, X86 64 LINUX, Nov 11 2020, Build ID 1502365`

WattEq:= r^2 - (b^2 - (a*sin(theta) + sqrt(c^2 - a^2*cos(theta)^2))^2):

params:= [a= 3.1, b= 1.1, c= 3.]:  rng:= -1.2..1.2:

W:= (evala @ Norm @ eval[recurse])(
    WattEq,
    #polar to cartesian:
    [r= sqrt(x^2+y^2), (cos,sin)(theta)=~ (x,y)/~r]
):

plots:-implicitplot(eval(W, params), (x,y)=~ rng,
                    scaling= constrained, factor=true);

Download Earl_impl.mw

@Lana That looks like a flaw in the InertForm:-Parse handling of angle-bracket constructor syntax, to me.

I'd be tempted to first correct the generated inert form, and then call value on the targeted inert constructor calls.

restart;

Str := "1/3*<3^(1/2), -3^(1/2), 3^(1/2), 0> -1/3*<3^(1/2), 3^(1/2), 3^(1/2), 0>+ <2,1,1,0>":
Set := {op(InertForm:-Parse( Str ))}:

Set := subs(`%\`<,>\``=`%<,>`,Set);

{-`%*`(`%/`(1, 3), `%<,>`(`%^`(3, `%/`(1, 2)), `%^`(3, `%/`(1, 2)), `%^`(3, `%/`(1, 2)), 0)), `%*`(`%/`(1, 3), `%<,>`(`%^`(3, `%/`(1, 2)), -`%^`(3, `%/`(1, 2)), `%^`(3, `%/`(1, 2)), 0)), `%<,>`(2, 1, 1, 0)}

subsindets(Set, specfunc(`%<,>`), value);

{-`%*`(`%/`(1, 3), Vector(4, {(1) = sqrt(3), (2) = sqrt(3), (3) = sqrt(3), (4) = 0})), `%*`(`%/`(1, 3), Vector(4, {(1) = sqrt(3), (2) = -sqrt(3), (3) = sqrt(3), (4) = 0})), Vector(4, {(1) = 2, (2) = 1, (3) = 1, (4) = 0})}

Download InertForm_angleconst.mw

[edit] I am supposing that you have some reason for not simply constructing your set of inert multiples of Vectors directly, using inert `%*` along with active calls to Vector. That would be simpler and more efficient than all this parsing of strings, etc, which you must currently be generating somehow. My guess is that you want the uniquification that %Vector calls have within a set -- and which actual Vectors do not have. Do you have a specific reason?

ps. I have submitted that generation of `%\`<,>\`` by InertForm:-Parse in a bug report.

@tomleslie Or perhaps,

indets(expr,       
       'specfunc'(anything,  
                  convert(FunctionAdvisor(':-known_functions',
                                          quiet),set)));

@AHSAN I'll try and help your understanding -- I've edited the worksheet to no longer show a call to the ApproximateInt command, since it does not show the same output as that command.

The procedure show produces intermediate steps -- which I based on part of your images.

Perhaps you'd be more content coding everything shown in your images.

I have deleted a duplicate of this Question.

You can add followup details or followup queries here, for this problem. Please don't submit new and separate Question threads for it.

I advise you to provide code that reproduces the problem. You could upload and attach a worksheet using the green up-arrow in the Mapleprimes editor.

What does it mean to you, for a plot to have a transparent background?

Do you mean it in the context of exporting, eg. as .GIF file?

What would the contour represent?

(Once you answer that first query) How many such contours do you think there are?

@AmirHosein Sadeghimanesh 

This user repeatedly asks Questions here without mentioning that he is using the older version Maple 2019. (I have now marked this Question with that version number.)

In Maple 2019 the Student:-Basics package did not contain the FactorSteps, SolveSteps, or SimplifiySteps commands.

Using a single left-quoted name as first argument to nprintf is technically weaker because it can be broken by the obscure possibility of prior assignment to that name.  As unlikely as that is possibility is, it is more defensive programming to prevent that breakage.

A string is the simplest, safer alternative. The alternative of a left single-quoted reference to the global right single-quoted is more complicated. In your example with curry that defensive alternative may require nested single left-quotes for such protective safety, at which point the process is far more complicated than simply using double-quotes. Eg,

restart;
`#mo("%s",mathcolor="%a");`:=oof:

cprint:= curry(nprintf, '':-`#mo("%s",mathcolor="%a");`''):

cprint("This is green", green);
cprint("This is green", red);

note: I know that Carl is well aware of all this. I mention it for the general readership.

@nm You might consider using the "Branch" icon at the bottom of your Question body (next to Reply/Answer.).

That should create a separate Question thread, but with cross-reference link added automatically.

The OP's attached worksheet executes without error for me in both Maple 2022.0 and Maple 2022.1 for Linux.

@ijuptilk You can augment that list, conts, with any value you choose. Below I include the min and max values from the generated Array of data.

In the case that the surface lies very close to its minimum (or maximum) over an area (not just points, or along curves) then there may be visual artefacts when the contour plot is rendered. I accomodate that by making a small offset to the contour values, which seems to satisfactorily make the artefact vanish.

As for an Array of the data, you already asked me about that. It was op([1,3],...) of the structure returned by plot3d. You can assign those to names of your choice. I do this below.

Recall that I mentioned before that you could construct an Array (or Matrix, or list of lists) of data either using a nested seq call, or using the plot3d command. I used the latter, as I think that makes the associated ranges easier for you to understand than for the corresponding increments for the seq calls..

By the way, given the Array of data, a you could also call listcontplot and obtain a similar result as contourplot (with the corresponding grid and ranges). You can transform the result to the corresponding ranges. See attached.

restart:

doCalc:= proc(xi, u)  #u is the \bar(H): normalize magnetic field magnitude,
                          # where H = bar(H)*H__a
                 option remember;
                 # Import Packages
                 uses ArrayTools, Student:-Calculus1, LinearAlgebra,
                      ListTools, RootFinding, plots, ListTools:
                 local gamma__1:= .1093,
                       alpha__3:= -0.1104e-2,
                       k__1:= 6*10^(-12),
                       d:= 0.2e-3,
                       theta0:= 0.1e-3,
                       eta__1:= 0.240e-1, chi:= 1.219*10^(-6),
                       alpha:= 1-alpha__3^2/(gamma__1*eta__1),
                       theta_init:= theta0*sin(Pi*z/d),
                       H__a:= Pi*sqrt(k__1/chi)/d,
                       H := u*H__a,     
                       c:=alpha__3*xi*alpha/(eta__1*(4*k__1*q^2/d^2-alpha__3*xi/eta__1 - chi*H^2)),
                       w := chi*H^2*eta__1*alpha/(4*k__1*q^2/d^2-alpha__3*xi/eta__1 - chi*H^2),
                       n:= 20,
                       g, f, b1, b2, qstar, OddAsymptotes, ModifiedOddAsym,
                       qstarTemporary, indexOfqstar2, qstar2, AreThereComplexRoots,
                       soln1, soln2, qcomplex1, qcomplex2, gg, qq, m, pp, j, i,
                       AllAsymptotes, p, Efun, b, aa, F, A, B, Ainv, r, theta_sol, v, Vfun, v_sol,minp,nstar;

                 if not [xi,u]::[numeric,numeric] then
                    return 'procname'(args);
                 end if;

# Assign g for q and plot g, Set q as a complex and Compute the Special Asymptotes

                 g:= q-(1-alpha)*tan(q)- (w*q + c)*tan(q):
                 f:= subs(q = x+I*y, g):
                 b1:= evalc(Re(f)) = 0:
                 b2:= evalc(Im(f)) = 0:
                 qstar:= (fsolve(1/c = 0, q = 0 .. infinity)):
                 OddAsymptotes:= Vector[row]([seq(evalhf(1/2*(2*j + 1)*Pi), j = 0 .. n)]);

# Compute Odd asymptote

                 ModifiedOddAsym:= abs(`-`~(OddAsymptotes, qstar));
                 qstarTemporary:= min(ModifiedOddAsym);
                 indexOfqstar2:= SearchAll(qstarTemporary, ModifiedOddAsym);
                 qstar2:= OddAsymptotes(indexOfqstar2);

# Compute Odd asymptote

                 AreThereComplexRoots:= type(true, 'truefalse');
                 try
                      soln1:= fsolve({b1, b2}, {x = min(qstar2, qstar) .. max(qstar2, qstar), y = 0 .. infinity});
                      soln2:= fsolve({b1, b2}, {x = min(qstar2, qstar) .. max(qstar2, qstar), y = -infinity .. 0});
                      qcomplex1:= subs(soln1, x+I*y);
                      qcomplex2:= subs(soln2, x+I*y);
                 catch:
                       AreThereComplexRoots:= type(FAIL, 'truefalse');
                 end try;

# Compute the rest of the Roots

                 #OddAsymptotes:= Vector[row]([seq(evalhf((1/2)*(2*j+1)*Pi), j = 0 .. n)]);
                 AllAsymptotes:= sort(Vector[row]([OddAsymptotes, qstar]));
                 if   AreThereComplexRoots
                 then
                      gg := [ qcomplex1,
                              qcomplex2,
                              op(Roots(g, q = 0.1e-3 .. AllAsymptotes[n], numeric))
                            ];
                 elif not AreThereComplexRoots
                 then gg:= [ op(Roots(g, q = 0.1e-3 .. AllAsymptotes[n], numeric))
                           ];
                 end if:

# Remove the repeated roots if any & Redefine n

                 qq:= MakeUnique(gg):
                 m:= numelems(qq):

## Compute the `&tau;_n`time constants

                 for i to m do
                 p[i] := evalf(gamma__1*alpha/(4*k__1*qq[i]^2/d^2 - alpha__3*xi/eta__1- chi*H^2)):
if not p[i]::complex(numeric) then print(p[i], [xi,u], qq[i]); end if;
                 end do:

                Digits := 15;
## Compute θ_n from initial conditions

                for i to m do
                Efun[i] := cos(qq[i]-2*qq[i]*z/d)-cos(qq[i]):
                end do:

## Compute integral coefficients for off-diagonal elements θ_n matrix

                printlevel := 2:
                for i to m do
                    for j from i+1 to m do
                        b[i, j] := evalf(Int(Efun[i]*Efun[j], z = 0 .. d)):
                        if not b[i, j]::complex(numeric) then
                            b[i, j] := evalf[15](Int(Efun[i]*Efun[j], z = 0 .. d,
                                                 digits=15, method=_Dexp, epsilon=1e-12)):
                            if not b[i, j]::complex(numeric) then
                               print("A",[Efun[i]*Efun[j], z = 0 .. d]);
                            end if;
                        end if;
                        b[j, i] := b[i, j]:
                        aa[i, j] := b[i, j]:
                        aa[j, i] := b[j, i]:
                    end do :
                end do:

## Calculate integral coefficients for diagonal elements in theta_n matrix

                for i to m do
                   aa[i, i] := evalf(Int(Efun[i]^2, z = 0 .. d)):
                   if not aa[i, i]::complex(numeric) then
                      aa[i, i] := evalf[15](Int(Efun[i]^2, z = 0 .. d,
                                                digits=15, epsilon=1e-12));
                      if not aa[i, i]::complex(numeric) then
                         print("B",[Efun[i]^2, z = 0 .. d]);
                      end if;
                   end if;
                end do:

## Calculate integrals for RHS vector

               for i to m do
               F[i] := evalf(Int(theta_init*Efun[i], z = 0 .. d));
               if not F[i]::complex(numeric) then
                  F[i] := evalf[15](Int(theta_init*Efun[i], z = 0 .. d,
                                     digits=15, method=_Dexp, epsilon=1e-12));
                  if not F[i]::complex(numeric) then
                     print("C",[theta_init*Efun[i], z = 0 .. d]);
                  end if;
               end if;
               end do:

## Create matrix A and RHS vector B

               A := Matrix([seq([seq(aa[i, j], i = 1 .. m)], j = 1 .. m)]):
               B := Vector([seq(F[i], i = 1 .. m)]):

## Calculate solve A*x=B

              r := LinearSolve(A,B);

## Define Theta(z,t)
             theta_sol := add(r[i]*Efun[i]*exp(-t/p[i]), i = 1 .. m):

## Compute v_n for n times constant

             for i to m do
             v[i] := (-2*k__1*alpha__3*qq[i])*(1/(d^2*eta__1*alpha*gamma__1))+ alpha__3^2*xi/(2*(eta__1)^2*qq[i]*alpha*gamma__1)+xi/(2*eta__1*qq[i]) + alpha__3*chi*H^2/(2*eta__1*qq[i]*gamma__1*alpha):
             end do:

## Compute v(z,t) from initial conditions
             for i to m do
             Vfun[i] := d*sin(qq[i]-2*qq[i]*z/d)+(2*z-d)*sin(qq[i]):
             end do:

## Define v(z,t)
             v_sol := add(v[i]*r[i]*Vfun[i]*exp(-t/p[i]), i = 1 .. m):

##
             minp:=min( seq( Re(p[i]), i=1..m) ):
             member(min(seq( Re(p[i]), i=1..m)),[seq( Re(p[i]), i=1..m)],'nstar'):

## Return all the plots
                 return theta_init, theta_sol, v_sol, minp, eval(p), nstar, p[nstar], g, H, H__a;
                 end proc:

# Run the calculation for supplied value of 'xi'

# Put the returned quantities in a simple list

ans:=CodeTools:-Usage([doCalc(-0.06, 0.001)]):
evalf(ans[9]);
evalf(ans[10]);

memory used=454.19MiB, alloc change=366.15MiB, cpu time=4.71s, real time=4.53s, gc time=486.75ms

0.3484926715e-1

34.84926715

with(plots):

d:= 0.2e-3:

testproc := proc(j, u, k) option remember;
   local calcvals;
   if not [j,u,k]::[numeric,numeric,posint] then
      return 'procname'(args);
   end if;
   calcvals:=doCalc(j,u);
   evalf(calcvals[k]);
end proc:

NN:=8; # number of values (excluding minv and maxv)

8

(gridji,rngj,rngi):=[11,21],1..3,-2.0..-0.0;
PP[gridji,4]:=CodeTools:- Usage(plot3d(max(-1e2,testproc(i,j,4)), j=rngj, i=rngi, grid=gridji)):

[11, 21], 1 .. 3, -2.0 .. -0.

memory used=105.53GiB, alloc change=160.00MiB, cpu time=18.98m, real time=16.00m, gc time=2.84m

PP[gridji,4];

data[gridji,4]:=op([1,3],PP[gridji,4]);

data[[11, 21], 4] := Vector(4, {(1) = ` 1..11 x 1..21 `*Array, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*C_order})

(minv,maxv):=[min,max](data[gridji,4])[];

-100., -2.78860304200000009

(color1,color2):="Red","Yellow":
conts:=[minv, seq(minv+(i-1)*(maxv-minv)/(NN+2-1),i=2..NN+1), maxv];

[-100., -89.19873367, -78.39746734, -67.59620101, -56.79493469, -45.99366836, -35.19240202, -24.39113570, -13.58986937, -2.78860304200000009]

colorlist:=ColorTools:-Color~(((c1,c2,N)->[seq(c1+(i-1)*(c2-c1)/(N-1),
                                               i=1..N)])([ColorTools:-Color(color2)[]],
                                                         [ColorTools:-Color(color1)[]],
                                                         nops(conts))):
#re-using values computed during plot3d on same grid.
CodeTools:- Usage(contourplot(max(-1e2,testproc(i,j,4)), j=rngj, i=rngi, grid=gridji,
                              contours=conts, thickness=0, coloring=[color1,color2],
                              filledregions, axes=boxed)):
PC:=subsindets(%,specfunc(anything,THICKNESS),u->THICKNESS(0.2)):
display(PC,
        seq(plot(-2.0,1..1,legend=evalf[4](conts[i]),thickness=15,
                 color=colorlist[nops(conts)-i+1],legendstyle=[location=right]),
            i=1..nops(conts)),
        size=[500,400]);

memory used=1.76MiB, alloc change=0 bytes, cpu time=59.00ms, real time=60.00ms, gc time=0ns

subsindets(plots:-listcontplot(Matrix(data[gridji,4]),
                               contours=conts-~1e-9,filledregions,thickness=0),
           specfunc(anything,THICKNESS),u->THICKNESS(0.2)):
LCP[gridji,4]:=plottools:-transform((x,y)->[lhs(rngj)+(rhs(rngj)-lhs(rngj))*(x-1)/(gridji[1]-1),
                                            lhs(rngi)+(rhs(rngi)-lhs(rngi))*(y-1)/(gridji[2]-1)])(%):
display(LCP[gridji,4],
        seq(plot(-2.0,1..1,legend=evalf[4](conts[i]),thickness=15,
                 color=colorlist[nops(conts)-i+1]),
            i=1..nops(conts)),
        size=[500,400],legendstyle=[location=right], axes=boxed);

(gridji,rngj,rngi):=[11,21],1..3,-2.0..-0.0;
PP[gridji,7]:=CodeTools:- Usage(plot3d(Im(testproc(i,j,7)), j=rngj, i=rngi, grid=gridji)):

[11, 21], 1 .. 3, -2.0 .. -0.

memory used=301.40KiB, alloc change=0 bytes, cpu time=3.00ms, real time=4.00ms, gc time=0ns

PP[gridji,7];

data[gridji,7]:=op([1,3],PP[gridji,7]);

data[[11, 21], 7] := Vector(4, {(1) = ` 1..11 x 1..21 `*Array, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*C_order})

(minv,maxv):=[min,max](data[gridji,7])[];

-36.4108769999999993, 0.

(color1,color2):="Red","Yellow":
conts:=[minv, seq(minv+(i-1)*(maxv-minv)/(NN+2-1),i=2..NN+1), maxv];

[-36.4108769999999993, -32.36522400, -28.31957100, -24.27391800, -20.22826500, -16.18261200, -12.13695900, -8.09130600, -4.04565300, 0.]

colorlist:=ColorTools:-Color~(((c1,c2,N)->[seq(c1+(i-1)*(c2-c1)/(N-1),
                                               i=1..N)])([ColorTools:-Color(color2)[]],
                                                         [ColorTools:-Color(color1)[]],
                                                         nops(conts))):
#re-using values computed during plot3d on same grid.
CodeTools:- Usage(contourplot(Im(testproc(i,j,7)), j=rngj, i=rngi, grid=gridji,
                              contours=conts-~1e-10, thickness=0, coloring=[color1,color2],
                              filledregions, axes=boxed)):
PC:=subsindets(%,specfunc(anything,THICKNESS),u->THICKNESS(0.2)):
display(PC,
        seq(plot(-2.0,1..1,legend=evalf[4](conts[i]),thickness=15,
                 color=colorlist[nops(conts)-i+1],legendstyle=[location=right]),
            i=1..nops(conts)),
        size=[500,400]);

memory used=1.49MiB, alloc change=0 bytes, cpu time=49.00ms, real time=51.00ms, gc time=0ns

subsindets(plots:-listcontplot(Matrix(data[gridji,7]),
                               contours=conts-~1e-9,filledregions,thickness=0),
           specfunc(anything,THICKNESS),u->THICKNESS(0.2)):
LCP[gridji,7]:=plottools:-transform((x,y)->[lhs(rngj)+(rhs(rngj)-lhs(rngj))*(x-1)/(gridji[1]-1),
                                            lhs(rngi)+(rhs(rngi)-lhs(rngi))*(y-1)/(gridji[2]-1)])(%):
display(LCP[gridji,7],
        seq(plot(-2.0,1..1,legend=evalf[4](conts[i]),thickness=15,
                 color=colorlist[nops(conts)-i+1]),
            i=1..nops(conts)),
        size=[500,400],legendstyle=[location=right], axes=boxed);

 

NULL

Download Case_3_IjuptilK_300522_ac_data.mw

@Rouben Rostamian  A friendly comment: one doesn't need the expense of unapply, merely to perform this substitution.

T := expr->eval(expr,[x=(sqrt(3)*y-x)/2,
                      y=(-sqrt(3)*y-x)/2]):
First 103 104 105 106 107 108 109 Last Page 105 of 591