acer

32303 Reputation

29 Badges

19 years, 310 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Your code is calling PRoc with argument s=94.24777963 .

And then, inside PRoc, m=s/A is 90.00000001. And then k=trunc(m)+1 is 91. And then in the call to pointplot you reference varphi[k]=varphi[91]. But the earlier code has only assigned varphi for indices from 1 to 90, and varphi[91] is unassigned and not numeric. So the pointplot call generates an error, because not all the points's coordinates are numeric.

So your problem seems (at least partly) due to a flaw in the animate routine, where it passes a value slightly outside your supplied range. That value of 94.24777963 is greater than the upper end-point of the range 0..Pieces*v*A that you passed to animate. (It's due to numeric roundoff error, I think, but not just because the value A contains the symbolic value Pi.)

You might try constructing your animation as follows. This does not call PRoc with a value higher than the upper end-point. (It's not the only way around your problem, but it avoids fiddling with PRoc.)

plots:-display([seq(PRoc(h),h=0..evalhf(Pieces*v*A),
                    numelems=110)],
               insequence=true);

reproduce_issue_ac.mw

For fun (done in Maple 2022.1).

restart;

eq1:=x+2*y=4;
eq2:=3*x+4*y=6;

x+2*y = 4

3*x+4*y = 6

Student:-Basics:-SolveSteps(eq1,x);

"[[,,"Let's solve"],[,,[]=4],["•",,"Subtract" 2*y "from both sides"],[,,[]=[]],["•",,"Simplify"],[,,x=[]],["•",,"Solution"],[,,x=4-2 y]]"

xsol:=Student:-Basics:-SolveSteps(eq1,x,
                                  output=record)[steps][-1][math];

x = 4-2*y

Substitute xsol into eq2

neweq2:=eval(eq2,xsol);

12-2*y = 6

Student:-Basics:-SolveSteps(neweq2,y);

"[[,,"Let's solve"],[,,[]=6],["•",,"Subtract" 12 "from both sides"],[,,[]=[]],["•",,"Simplify"],[,,[]=-6],["•",,"Divide both sides by" -2],[,,[]=[]],["•",,"Simplify"],[,,y=3]]"

yans:=Student:-Basics:-SolveSteps(neweq2,y,
                                  output=record )[steps][-1][math];

y = 3

Substitute yans into xsol

xans:=eval(xsol,yans);

x = -2

xans,yans;

x = -2, y = 3

Download SolveSteps_twice.mw

Writing a procedure for Newton's method is easy, and you should be able to find several implementations with a quick search of this forum. That kind of functionality is also provided by some stock Library commands, eg,

with(Student):
Calculus1:-NewtonsMethod( x^3+x+1, x=-1,
                          iterations=4, output=sequence );

  -1, -0.7500000000, -0.6860465116, -0.6823395824, -0.6823278040

NumericalAnalysis:-Roots( x^3+x+1, x=-1, method=newton,
                          tolerance=1e-09, output=sequence);

  -1., -0.7500000000, -0.6860465116, -0.6823395824, -0.6823278040, -0.6823278040

Instead, I will show below a scheme that reproduces the step-by-step computations as shown in your image. After all, that is what you specifically requested in your Question. (Done in Maple 2019)

restart;

NewtStep := proc(expr::scalar, var::name, init::numeric,
                 {steps::posint:=1, simplify::truefalse:=false})
  local dexpr, i, form, sform, this, val, x;
  uses Typesetting;
  dexpr := diff(expr, var);
  val[0] := init;
  form := x[i] - eval(expr, var=x[i])/eval(dexpr, var=x[i]);
  if simplify then sform := :-simplify(form); end if;
  print(mrow(eval('Typeset'(x[i+1])),
             mo("="),
             eval('Typeset'(x[i]-'f'(x[i])/Eval(diff('f'(var),var),var=x[i]))),
             mo("="),
             eval('Typeset'(form)),
             `if`(simplify and form<>sform,
                  [mo("&equals;"), eval('Typeset'(sform))][],
                  NULL),
             mo("   i=0,1,2,..."))); print();
  if simplify then form := sform; end if;
  print( x[0] = val[0] );
  for i from 0 to steps-1 do
    this := eval(form);
    val[i+1] := evalf(eval(this, x[i]=val[i]));
    print(mrow(eval('Typeset'(x[i+1])),
               mo("&equals;"),
               eval('Typeset'(this)),
               mo("&equals;"),
               eval('Typeset'(eval(this,x[i]=mfenced(mn(sprintf("%a",val[i])))))),
               mo("&equals;"),
               eval('Typeset'(val[i+1]))));
  end do:
end proc:

NewtStep( x^3 + x + 1, x, -1 );

"x[i+1]=x[i]-(f(x[i]))/(((&DifferentialD;)/(&DifferentialD;x) f(x)) ? ()|() ? (x=x[i]))=x[i]-(x[i]^3+x[i]+1)/(3 x[i]^2+1)   i=0,1,2,..."

x[0] = -1

x[1] = x[0]-(x[0]^3+x[0]+1)/(3*x[0]^2+1) and x[0]-(x[0]^3+x[0]+1)/(3*x[0]^2+1) = -1-((-1)^3-1+1)/(3*(-1)^2+1) and -1-((-1)^3-1+1)/(3*(-1)^2+1) = -.7500000000

NewtStep( x^3 + x + 1, x, -1, steps=3, simplify );

"x[i+1]=x[i]-(f(x[i]))/(((&DifferentialD;)/(&DifferentialD;x) f(x)) ? ()|() ? (x=x[i]))=x[i]-(x[i]^3+x[i]+1)/(3 x[i]^2+1)=(2 x[i]^3-1)/(3 x[i]^2+1)   i=0,1,2,..."

x[0] = -1

x[1] = (2*x[0]^3-1)/(3*x[0]^2+1) and (2*x[0]^3-1)/(3*x[0]^2+1) = (2*(-1)^3-1)/(3*(-1)^2+1) and (2*(-1)^3-1)/(3*(-1)^2+1) = -.7500000000

x[2] = (2*x[1]^3-1)/(3*x[1]^2+1) and (2*x[1]^3-1)/(3*x[1]^2+1) = (2*(-.7500000000)^3-1)/(3*(-.7500000000)^2+1) and (2*(-.7500000000)^3-1)/(3*(-.7500000000)^2+1) = -.6860465116

x[3] = (2*x[2]^3-1)/(3*x[2]^2+1) and (2*x[2]^3-1)/(3*x[2]^2+1) = (2*(-.6860465116)^3-1)/(3*(-.6860465116)^2+1) and (2*(-.6860465116)^3-1)/(3*(-.6860465116)^2+1) = -.6823395827

Download NewtStep.mw

The first argument (a string) needs to keep its double-quotes inside the constructed name. So you could use the %a modifier for it, in nprintf.

Your problem is the disappearance of those quotes, in the name construction. That first use in your nprintf call of the %A modifier -- without any wrapping, escaped, double-quotes in the format -- is the mistake.

Also, technically the constructed name should end with a semicolon. (In modern version it can work without it for regular output, but there are some scenarios in plotting where it is necessary to get the typeset effect.)

One solution is:

cprint:=proc(s::string,c)
  nprintf("#mo(%a,mathcolor=\"%a\");",s,c);
end proc:

cprint("this is green",green);

cprint("this is green",red);

Another solution (which handles both strings and plain names as the first argument) is:

cprint:=proc(s,c)
  nprintf("#mo(\"%A\",mathcolor=\"%a\");",s,c);
end proc:

cprint("this is green",green);

cprint("this is green",red);

cprint(soliton,purple);

There are various other alternatives.

You mentioned the TangentLine command, so here's one way to use that.

I'll include two examples: one implicit in both x & y, and one explicit in y. You didn't mention which your "curve" might be. The Calculus1:-Tangent command is an alternative for explicit examples.

restart;

with(plots): with(Student:-VectorCalculus,TangentLine):

 

expr := 2/3*x^2 + y^2 -x*y/2 = 1;

(2/3)*x^2+y^2-(1/2)*x*y = 1

xpt := 0;

0

ypt := solve(eval(expr,x=xpt), y, maxsols=1); # or fsolve

1

TL := TangentLine(expr, x=xpt, y=ypt);

-(1/2)*x+2*y-2 = 0

display(
  implicitplot([expr, TL], x=-2..2, y=-2..2, color=[red,blue]),
  pointplot([[xpt,ypt]], symbol=circle, symbolsize=15)
);

expr := y = x^2+3*x+1+20*sin(x)-log(x);

y = x^2+3*x+1+20*sin(x)-ln(x)

xpt := 2;

2

ypt := solve(eval(expr,x=xpt), y, maxsols=1); # or fsolve

11+20*sin(2)-ln(2)

TL := TangentLine(expr, x=xpt, y=ypt);

(-13/2-20*cos(2))*(x-2)+y-11-20*sin(2)+ln(2) = 0

display(
  implicitplot([expr, TL], x=-2..6, y=0..40, color=[red,blue]),
  pointplot([[xpt,ypt]], symbol=circle, symbolsize=15)
);

Download TangentLine_ex.mw

I could have used the plot command for the lines, but I thought it looked slightly simpler with passing both the line and the curve's expression to implicitplot.

You could choose to work consistently with either all floats or all exact values, when calling Rank.

In the float case you may need all the floats to have at least the same accuracy up to the working precision with which Rank is performed. (In other examples or scenarios that can get trickier.)

For your particular example, you could get by with these:

restart;

CorrBasis := {<sqrt(3),2,0>, <0,1/5,1>}:
CorrMat := evalf(Matrix([op(CorrBasis)]));
Basis := {<3^(0.5), 2., 0.>, <0.,0.2,1.>}:

Matrix(3, 2, {(1, 1) = 0., (1, 2) = 1.732050808, (2, 1) = .2000000000, (2, 2) = 2., (3, 1) = 1., (3, 2) = 0.})

remove(i -> is(LinearAlgebra:-Rank(<CorrMat|i>) <> nops(CorrBasis)),  Basis);

{Vector(3, {(1) = 0., (2) = .2, (3) = 1.}), Vector(3, {(1) = 1.732050808, (2) = 2., (3) = 0.})}

restart;

CorrBasis := {<sqrt(3),2,0>, <0,1/5,1>}:
CorrMat := Matrix([op(CorrBasis)]);
Basis := {<3^(0.5), 2., 0.>, <0.,0.2,1.>}:

Matrix(3, 2, {(1, 1) = 0, (1, 2) = sqrt(3), (2, 1) = 1/5, (2, 2) = 2, (3, 1) = 1, (3, 2) = 0})

remove(i -> is(LinearAlgebra:-Rank(evalf(<CorrMat|i>)) <> nops(CorrBasis)),  Basis);

{Vector(3, {(1) = 1.732050808, (2) = 2., (3) = 0.}), Vector(3, {(1) = 0., (2) = .2, (3) = 1.})}

restart;

CorrBasis := {<sqrt(3),2,0>, <0,1/5,1>}:
CorrMat := Matrix([op(CorrBasis)]);
Basis := {<3^(1/2), 2, 0>, <0,2/10,1>}:

Matrix(3, 2, {(1, 1) = 0, (1, 2) = sqrt(3), (2, 1) = 1/5, (2, 2) = 2, (3, 1) = 1, (3, 2) = 0})

remove(i -> is(LinearAlgebra:-Rank(evalf(<CorrMat|i>)) <> nops(CorrBasis)),  Basis);

{Vector(3, {(1) = sqrt(3), (2) = 2, (3) = 0}), Vector(3, {(1) = 0, (2) = 1/5, (3) = 1})}

 

Download bas.mw

You had also tried using the plot command, so I'll show how alternatively you could use that command.

Note that I use the axiscoordinates=polar option as well as the coords=polar option.

Note that it still helps to restrict the coordinateview, so that the horizontal offset of the vertical line is clear.

plot( 2/cos(theta), coordinateview=[0..4,0..2*Pi],
      coords = polar, axiscoordinates=polar );

restart;

m := 1: n := 2:

Zc := m*cos(1/180*x*Pi) + n*cos(1/180*y*Pi);

cos((1/180)*x*Pi)+2*cos((1/180)*y*Pi)

Zs := m*sin(1/180*x*Pi) + n*sin(1/180*y*Pi);

sin((1/180)*x*Pi)+2*sin((1/180)*y*Pi)

Optimization:-Maximize(Zs, {Zc=Zs}, x=0..180, y=0..180);

[2.12132034355964283, [x = HFloat(44.99999999999951), y = HFloat(45.00000000000025)]]

obj := max(extrema(Zs, {Zc=Zs}, {x,y}, 's'));

(3/2)*2^(1/2)

select(u->eval(Zs,u)=obj, s);

{{x = 45, y = 45}}

evalf(obj);

2.121320343

Download opt_examp.mw

Here's one way to get contour plots of the 4th and (Im of) the 7th elements of the expression sequence returned by the doCalc procedure.

A few changes:
  - option remember, to all query for different elements of doCalc's output, while only incurring the cost once for a given grid-resolution.
  - cap lower values (can be very large-negative when first parameter of doCalc is close to 0.0), since otherwise the qualitative features in the -100..0.0 range of output are generally missed by the contours.
  - use plot3d as convernient mechanism to precalculate at desired (shared) grid spacing, where subsequent plot3d/contourplot at the very same grid values will then be very fast.
  - bolster numeric integration, which slows it all down but helps avoid holes in the output data by being more robust.

Naturally, you could invert the order of the legend items.

I didn't bother trying to use the Grid package to parallelize the initial computation of calling doCalc over the shared grid (input) values. I expect that -- with care -- it could be done, instead of these using initial plot3d calls.

I do each (of 4th, and Im of 7th) at first on a coarse grid, and then again on a finer grid.

I used Maple 18.02.  (Later versions allow slightly easier construction of these legend items for a contourplot, or more sophisticated multi-color gradient shading for densityplot.)

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=455.22MiB, alloc change=366.71MiB, cpu time=4.48s, real time=4.04s, gc time=650.56ms

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:

nconts:=8;

8

(gridji,rngj,rngi):=[3,21],1..3,-2.0..-0.0;
CodeTools:- Usage(plot3d(max(-1e2,testproc(i,j,4)), j=rngj, i=rngi, grid=gridji)):
(minv,maxv):=[min,max](op([1,3],%))[]:
(color1,color2):="Red","Yellow":
conts:=[seq(minv+(i-1)*(maxv-minv)/(nconts+2-1),i=1..nconts+2)][2..nconts+1]:
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]);

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

memory used=28.46GiB, alloc change=128.00MiB, cpu time=5.72m, real time=4.96m, gc time=38.80s
memory used=0.79MiB, alloc change=0 bytes, cpu time=14.00ms, real time=15.00ms, gc time=0ns

(gridji,rngj,rngi):=[3,21],1..3,-2.0..-0.0;
CodeTools:- Usage(plot3d(Im(testproc(i,j,7)), j=rngj, i=rngi, grid=gridji)):
(minv,maxv):=[min,max](op([1,3],%))[]:
(color1,color2):="Red","Yellow":
conts:=[seq(minv+(i-1)*(maxv-minv)/(nconts+2-1),i=1..nconts+2)][2..nconts+1]:
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, 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]);

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

memory used=225.37KiB, alloc change=0 bytes, cpu time=6.00ms, real time=7.00ms, gc time=0ns
memory used=0.56MiB, alloc change=0 bytes, cpu time=24.00ms, real time=25.00ms, gc time=0ns

(gridji,rngj,rngi):=[11,31],1..3,-2.0..-0.0;
CodeTools:- Usage(plot3d(max(-1e2,testproc(i,j,4)), j=rngj, i=rngi, grid=gridji)):
(minv,maxv):=[min,max](op([1,3],%))[]:
(color1,color2):="Red","Yellow":
conts:=[seq(minv+(i-1)*(maxv-minv)/(nconts+1-1),i=1..nconts+1)][1..nconts];
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))):
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]);

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

memory used=155.38GiB, alloc change=64.00MiB, cpu time=36.43m, real time=31.42m, gc time=7.83m

[-100., -87.84549593, -75.69099186, -63.53648780, -51.38198374, -39.22747968, -27.07297560, -14.91847154]

memory used=1.87MiB, alloc change=0 bytes, cpu time=44.00ms, real time=44.00ms, gc time=0ns

(gridji,rngj,rngi):=[11,31],1..3,-2.0..-0.0;
CodeTools:- Usage(plot3d(Im(testproc(i,j,7)), j=rngj, i=rngi, grid=gridji)):
(minv,maxv):=[min,max](op([1,3],%))[]:
(color1,color2):="Red","Yellow":
conts:=[seq(minv+(i-1)*(maxv-minv)/(nconts+1-1),i=1..nconts+1)][1..nconts];
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))):
CodeTools:- Usage(contourplot(Im(testproc(i,j,7)), 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]);

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

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

[-45.51593608, -39.82644407, -34.13695206, -28.44746006, -22.75796804, -17.06847603, -11.37898402, -5.68949200]

memory used=1.59MiB, alloc change=0 bytes, cpu time=39.00ms, real time=39.00ms, gc time=0ns

 

``

Download Case_3_IjuptilK_300522_ac8.mw

These worked for me in both Maple 2021.2 and 2022.0

restart;

GG:=GroupTheory:-Generators(GroupTheory:-SmallGroup(60,10));

[_m140504181456736, _m140504181470336, _m140504181472384, _m140504181472576]

latex(GG,output=string);

"[(1,2)(3,8)(4,9)(5,10)(6,12)(7,11)(13,23)(14,24)(15,26)(16,25)(17,28)(18,27)(19,30)(20,29)(21,32)(22,31)(33,44)(34,43)(35,46)(36,45)(37,48)(38,47)(39,50)(40,49)(41,52)(42,51)(53,58)(54,57)(55,60)(56,59), (1,3)(2,8)(4,13)(5,14)(6,15)(7,16)(9,23)(10,24)(11,25)(12,26)(17,33)(18,34)(19,35)(20,36)(21,37)(22,38)(27,43)(28,44)(29,45)(30,46)(31,47)(32,48)(39,53)(40,54)(41,55)(42,56)(49,57)(50,58)(51,59)(52,60), (1,4,5)(2,9,10)(3,13,14)(6,17,19)(7,18,20)(8,23,24)(11,27,29)(12,28,30)(15,33,35)(16,34,36)(21,39,41)(22,40,42)(25,43,45)(26,44,46)(31,49,51)(32,50,52)(37,53,55)(38,54,56)(47,57,59)(48,58,60), (1,6,21,22,7)(2,11,31,32,12)(3,15,37,38,16)(4,17,39,40,18)(5,19,41,42,20)(8,25,47,48,26)(9,27,49,50,28)(10,29,51,52,30)(13,33,53,54,34)(14,35,55,56,36)(23,43,57,58,44)(24,45,59,60,46)]"

# I also had no trouble Copy&Pasting this output.
latex(GG);

[
(1,2)(3,8)(4,9)(5,10)(6,12)(7,11)(13,23)(14,24)(15,26)(16,25)(17,28)(18,27)(19,30)(20,29)(21,32)(22,31)(33,44)(34,43)(35,46)(36,45)(37,48)(38,47)(39,50)(40,49)(41,52)(42,51)(53,58)(54,57)(55,60)(56,59)
,
(1,3)(2,8)(4,13)(5,14)(6,15)(7,16)(9,23)(10,24)(11,25)(12,26)(17,33)(18,34)(19,35)(20,36)(21,37)(22,38)(27,43)(28,44)(29,45)(30,46)(31,47)(32,48)(39,53)(40,54)(41,55)(42,56)(49,57)(50,58)(51,59)(52,60)
,
(1,4,5)(2,9,10)(3,13,14)(6,17,19)(7,18,20)(8,23,24)(11,27,29)(12,28,30)(15,33,35)(16,34,36)(21,39,41)(22,40,42)(25,43,45)(26,44,46)(31,49,51)(32,50,52)(37,53,55)(38,54,56)(47,57,59)(48,58,60)
,
(1,6,21,22,7)(2,11,31,32,12)(3,15,37,38,16)(4,17,39,40,18)(5,19,41,42,20)(8,25,47,48,26)(9,27,49,50,28)(10,29,51,52,30)(13,33,53,54,34)(14,35,55,56,36)(23,43,57,58,44)(24,45,59,60,46)
]

Download Perm_ltx.mw

You don't need to nest two calls to collect, in order to obtain your desired result.

restart;

eq_e5_10z := Psi[q0]*Delta*delta = 1/(omega[0])*p*(Delta*Psi[q])
             + Delta*Psi[d]+Psi[d0]*1/(omega[0])*p*(Delta*delta):

eq_e5_10za := Delta*Psi[d] = Psi[q0]*Delta*delta
              - op(1,rhs(eq_e5_10z)) - op(3,rhs(eq_e5_10z)):

eq_e5_10zb := algsubs(p*(Delta*Psi[q])=0,eq_e5_10za):

expr := rhs(eq_e5_10zb);

Psi[q0]*Delta*delta-Psi[d0]*p*Delta*delta/omega[0]

collect(expr,[delta,Delta]);

(Psi[q0]-Psi[d0]*p/omega[0])*Delta*delta

Download collect_d.mw

You're "desired" output contains the name p as standalone multiplicative factor (ie. not as a function call), hence it is clear that in your input you intended multiplication like  p*(Delta*delta)  and  p*(Delta*Psi[q])  and not unevaluated functions calls such as p(Delta*delta)  and  p(Delta*Psi[q]). Hence it seems that you have made a syntax mistake by using function call syntax and mistakenly expected it to denote multiplication.

A simpler example: f(x)  means f applied to x. It doesn't denote f*x.

You could also use eval, or assign on (the assumed) A and B.

restart;

assume(A < B);

S := 2/(B-A);

2/(B-A)

eval(S, [B=10, A=5]);

2/5

assign(B=10, A=5);

S;

2/5

Download assume_assign.mw

This is a frequently asked question.

Your Question's title contains a call to the root command. See the Description in the Help page for the root command for one explanation -- including explanation for this very example. As it mentions, the root command returns the principal root, which may not be a real root.

As alluded to in that page, you might alternatively utilize the surd command:

surd(-8,3);

           -2

You might also get what you want for this example with the RealDomain package (though it is not so robust as some people wish),

restart;
with(RealDomain):

(-8)^(1/3);

           -2

Inside a string (ie. inside a pair of double-quotes) you have to escape inner double-quotes with the backslash character, ie. \"

See also here.

a:=[["{\"test1\",\"test2\"}"],["{test3\",\"test4\"}"]];

[["{"test1","test2"}"], ["{test3","test4"}"]]

lprint(a);

[["{\"test1\",\"test2\"}"], ["{test3\",\"test4\"}"]]

parse(a[1,1]);

{"test1", "test2"}

lprint(%);

{"test1", "test2"}

Download escaped_quotes.mw

Here's an example, done in both 1D and 2D input modes.

I still think you ought to show us how exactly how it's gone wrong for you, with an example in an uploaded attached worksheet.

restart;

kernelopts(version);

`Maple 18.02, X86 64 LINUX, Oct 20 2014, Build ID 991181`

f := proc(x)
  global G;
  local y;
  y := x^2;
  G := y - 2;
  return y;
end proc:

f(3);

9

G;

7

ff := proc (x) local y; global G; y := x^2; G := y-2; return y end proc:

ff(7);

49

G;

47

Download proc_ex.mw

First 66 67 68 69 70 71 72 Last Page 68 of 336