acer

32385 Reputation

29 Badges

19 years, 343 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You can construct the plot in several ways.

You can also construct the list D1 in several ways. Your could express the difference of the products using special function GAMMA (or binomial or factorial, which I have not done, though there is the 1/2 present). You could also compute it with explicit multiplication, and by storing prior results to avoid recomputation (which I have not done as efficiency doesn't seem to be a central concern for your range of n).

restart

delta := 1/2

1/2

expr := simplify(product(1-1/(1+k)+3*delta/(1+k), k = 1 .. n)-product(1-(1-delta)/(1+k), k = 1 .. n))

(4/3)*n*GAMMA(3/2+n)/(Pi^(1/2)*GAMMA(2+n))

plot([1/(1+n), expr, n = 1 .. 10], adaptive = false, numpoints = 10, style = pointline, symbolsize = 15)

A := [seq(1/(1+n), n = 1 .. 10)]

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

D1 := [seq(product(3*delta*A[k]-A[k]+1, k = 1 .. n)-product(1-A[k]*(1-delta), k = 1 .. n), n = 1 .. 10)]

[1/2, 5/6, 35/32, 21/16, 385/256, 429/256, 15015/8192, 12155/6144, 138567/65536, 146965/65536]

D1 := [seq(expr, n = 1 .. 10)]

[1/2, 5/6, 35/32, 21/16, 385/256, 429/256, 15015/8192, 12155/6144, 138567/65536, 146965/65536]

P1 := plot(A, D1, style = point, color = blue, symbol = solidcircle, symbolsize = 15)

P2 := plot([1/(1+n), expr, n = 1 .. 10])

plots:-display(P2, P1)

 

Download Help_exclam_ac.mw

You wrote, "But now I am starting to worry that each maple command/function/name used inside the Object needs  :- added to it, just in case of a current or future name conflict with local object variables names."

But that is already true for programming with procedures and modules, so why suggest that it makes Object programming too onerous?

If there is a procedure or module local or the same name within scope then (within a procedure) one needs to qualify the name with colon-minus in order to force the interpretation to be the global instance of the name. (Your Questions first sentences incorrectly suggest the opposite, IMO.)

You might find it more convenient (or even proper) to exclude the non-static Object local (within scope) from being a candidate for the scoping resolution of the name reference. But it does not follow from your incorrect suggestion that the scoping rules are wholly different from that in general.

Use the Maple read command to read in a .m file that has been stored by Maple.

Pass the read command a string that points to the filename. It can be either the name/location relative to the current directory (see currentdir), or the full path to the file.

You can use the nextperm command from the combinat package to obtain the permutations one at a time. You don't need to construct your own procedure that walks the permutations.

You could also use the Iterator package to generate the permutations one at a time.

Having said that, here are three variants.

The first is like your original, but looks very awkward in Maple since I deliberately made almost as few alterations as possible to suit the language. You should not program like this in Maple, as there are much better techniques and syntax, even if you really feel the need to program the whole permutation process. But it is an answer to what you actually requested, about passing by reference (like a pointer). I use the evaln modifier of the procedure parameters so that they get passed by reference, and I use the eval command to access their values for the re-assignment.

The second is similar, but uses direct Array reference and multiple-assignment to swap entries.

And the third uses combinat:-nextperm.  I deliberately made the do-loop clumsy and obvious. It could be slicker (since Maple's do-loops also allow for useful while and until clauses, etc) but I hoped to confusion and it's not clear how you want to utilize the individual permutations.

restart;

swap := proc(a::evaln, b::evaln)
  local temp;
  temp := eval(a);
  a := eval(b);
  b := temp;
  return NULL;
end proc:

permutation := proc(arr, start::integer, End::integer)
  local i::integer;
  if start = End then
    print(arr);
    return NULL;
  end if;
  for i from start to End do
    swap(arr[i], arr[start]);
    procname(arr, start+1, End);
    swap(arr[i], arr[start]);
  end do;
  return NULL;
end proc:

A := Array(1..6, [a,b,c,d,e,f,g]);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

permutation(A, 4, 6);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = f, (6) = e})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = d, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = f, (6) = d})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = f, (5) = e, (6) = d})

Array(%id = 18446883908681703422)

A;

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

restart;

permutation := proc(arr, start::integer, End::integer)
  local i::integer;
  if start = End then
    print(arr);
    return NULL;
  end if;
  for i from start to End do
    arr[i],arr[start] := arr[start],arr[i];
    procname(arr, start+1, End);
    arr[i],arr[start] := arr[start],arr[i];
  end do;
  return NULL;
end proc:

A := Array(1..6, [a,b,c,d,e,f,g]);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

permutation(A, 4, 6);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = f, (6) = e})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = d, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = f, (6) = d})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = f, (5) = e, (6) = d})

Array(%id = 18446883908681703422)

A;

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

restart;

permutation:=proc(arr, start::integer, End::integer)
  local i,L,oldL,orig;
  uses combinat;
  L := [seq(i, i=start..End)];
  orig := arr[L];
  print(arr);
  do
    oldL,L := L,nextperm(L);
    if L = FAIL then break;
    else
      arr[L] := arr[oldL];
      print(arr);
    end if;
  end do;
  arr[[seq(i, i=start..End)]] := orig;
  return NULL;
end proc:

A := Array(1..6, [a,b,c,d,e,f,g]);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

permutation(A, 4, 6);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = f, (6) = e})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = d, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = f, (5) = d, (6) = e})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = f, (6) = d})

Array(%id = 18446883908681703662)

A;

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

 

Download perm.mw

If I have pasted in the plaintext theta__xy while in 2D Input mode then I can immediately convert it to the typeset form by simplify pressing the Escape key.

And I can do the same thing after the fact (ie. later) by first placing the mouse focus on that literal input, and then pressing Escape.

I don't know of any mechanism to change all such paste-ins with just one action, after the fact.

Is this adequate for your purpose?

Applying the expand command will turn the composition into nested calls, on which value does what you wanted.

restart;

with(Physics[Vectors]):

(%Nabla)(f(x,y,z));

%Nabla(f(x, y, z))

value(%);

(diff(f(x, y, z), x))*_i+(diff(f(x, y, z), y))*_j+(diff(f(x, y, z), z))*_k

(%Nabla@@4)(f(x,y,z));

(%Nabla@@4)(f(x, y, z))

value(expand(%));

diff(diff(diff(diff(f(x, y, z), x), x), x), x)+2*(diff(diff(diff(diff(f(x, y, z), x), x), y), y))+2*(diff(diff(diff(diff(f(x, y, z), x), x), z), z))+diff(diff(diff(diff(f(x, y, z), y), y), y), y)+2*(diff(diff(diff(diff(f(x, y, z), y), y), z), z))+diff(diff(diff(diff(f(x, y, z), z), z), z), z)

(Nabla@@4)(f(x,y,z));

diff(diff(diff(diff(f(x, y, z), x), x), x), x)+2*(diff(diff(diff(diff(f(x, y, z), x), x), y), y))+2*(diff(diff(diff(diff(f(x, y, z), x), x), z), z))+diff(diff(diff(diff(f(x, y, z), y), y), y), y)+2*(diff(diff(diff(diff(f(x, y, z), y), y), z), z))+diff(diff(diff(diff(f(x, y, z), z), z), z), z)

 

expand( (%Nabla@@4)(f(x,y,z)) );

%Nabla(%Nabla(%Nabla(%Nabla(f(x, y, z)))))

value(%);

diff(diff(diff(diff(f(x, y, z), x), x), x), x)+2*(diff(diff(diff(diff(f(x, y, z), x), x), y), y))+2*(diff(diff(diff(diff(f(x, y, z), x), x), z), z))+diff(diff(diff(diff(f(x, y, z), y), y), y), y)+2*(diff(diff(diff(diff(f(x, y, z), y), y), z), z))+diff(diff(diff(diff(f(x, y, z), z), z), z), z)

 

Download nested_comp.mw

Are you trying to say that you want it substituted by sigma literally, or that you just want a factor of Ls pulled out of the particular subterm?

restart;

LD := Lambda_ds = (-Lm^2/Lr + Ls)*i_ds + Lm*Lambda_dr/Lr;

Lambda_ds = (-Lm^2/Lr+Ls)*i_ds+Lm*Lambda_dr/Lr

sigma := (1-Lm^2/(Ls*Lr));

1-Lm^2/(Ls*Lr)

new := subs(ss=Ls*sigma, algsubs(Ls*sigma=ss,LD));

Lambda_ds = i_ds*Ls*(1-Lm^2/(Ls*Lr))+Lm*Lambda_dr/Lr

simplify(new - LD);

0 = 0

restart;

LD := Lambda_ds = (-Lm^2/Lr + Ls)*i_ds + Lm*Lambda_dr/Lr;

Lambda_ds = (-Lm^2/Lr+Ls)*i_ds+Lm*Lambda_dr/Lr

new := subs(ss=Ls*sigma, algsubs(Ls*(1-Lm^2/(Ls*Lr))=ss,LD));

Lambda_ds = i_ds*Ls*sigma+Lm*Lambda_dr/Lr

simplify(eval(new, sigma=(1-Lm^2/(Ls*Lr))) - LD);

0 = 0

 

Download question20200618_ac.mw

The dsolve parameter list is wrong in several places, and contains hidden 2D Input characters. That problem might also occur for the A in the initialvalues list passed to Minimize, and possibly also for the parameter sequence in the definition of procedure sse. You may be able to correct it in 2D Input by deleting the A character insteances and typing it in again. You'd likely be better off not using 2D Input mode, as it's clearly problematic for you.

You seem to be missing initial conditions, because the input line which assigns to ic has several statements broken by colons. You very likely should change those to a comma-separated sequence of equations instead.

The add call inside your sse procedure is not set up to handle the case that the result from select is an empty list. (In that case, it would pass NULL to rhs and throw an error.) It looks as if your select call might be an attempt to extract just one of the dsolve results solution procedures, is that right? Iso, then which one? Is it C(T)?

You may need to specifiy ranges for the parameters, in the call to Minimize.

You may need to adjust procedure sse so that it handles the case of a singularity in the numeric solution. (try..catch and return a large value? Something else?)

Your worksheet has a colon terminating the line with the call to Minimize. You likely would be better off not supressing that output, to see how it does.

You could apply this command.

restart;

expr := sqrt(abs(w[1]^2-2*w[1]*w[2]+w[2]^2
                 +x[1]^2-2*x[1]*x[2]+x[2]^2
                 +y[1]^2-2*y[1]*y[2]+y[2]^2
                 +(z[1]-z[2])^2));

abs(w[1]^2-2*w[1]*w[2]+w[2]^2+x[1]^2-2*x[1]*x[2]+x[2]^2+y[1]^2-2*y[1]*y[2]+y[2]^2+(z[1]-z[2])^2)^(1/2)

Student:-Precalculus:-CompleteSquare(expr);

abs((z[2]-z[1])^2+(y[2]-y[1])^2+(x[2]-x[1])^2+(w[2]-w[1])^2)^(1/2)

 

Download SPCSq.mw

Look at the computations and figure out what purpose they might serve in addressing any of the questions.

restart;

f := 19*(5*x/2+x*y-5*y-y^3+y^2/8-x^2/4+exp(y-20));

(95/2)*x+19*x*y-95*y-19*y^3+(19/8)*y^2-(19/4)*x^2+19*exp(y-20)

plot3d(f, x=-10..15, y=-3..3, view=-100..800.0);

S1 := fsolve({diff(f,x),diff(f,y)},{x=-10..15, y=-3..3});

{x = 6.500000004, y = .7500000019}

S2 := fsolve({diff(f,x),diff(f,y)},{x=-10..15, y=-3..3}, avoid={S1});

{x = 4.999999998, y = -0.9182986828e-9}

# fsolve does not find any more in this range
fsolve({diff(f,x),diff(f,y)},{x=-10..15, y=-3..3}, avoid={S1, S2});

fsolve({95/2+19*y-(19/2)*x, 19*x-95-57*y^2+(19/4)*y+19*exp(y-20)}, {x, y}, {x = -10 .. 15, y = -3 .. 3}, avoid = {{x = 4.999999998, y = -0.9182986828e-9}, {x = 6.500000004, y = .7500000019}})

Student:-MultivariateCalculus:-SecondDerivativeTest(f, [x,y]=eval([x,y],S1));

LocalMin = [], LocalMax = [[6.500000004, .7500000019]], Saddle = []

Student:-MultivariateCalculus:-SecondDerivativeTest(f, [x,y]=eval([x,y],S2));

LocalMin = [], LocalMax = [], Saddle = [[4.999999998, -0.9182986828e-9]]

H := :-VectorCalculus:-Hessian(f,[x,y]);

Matrix(2, 2, {(1, 1) = -19/2, (1, 2) = 19, (2, 1) = 19, (2, 2) = -114*y+19/4+19*exp(y-20)})

#
# These are all strictly negative
#
LinearAlgebra:-Eigenvalues( Matrix(eval(H, S1), shape=symmetric) );

Vector(2, {(1) = -85.5000001317647, (2) = -4.750000008235295})

#
# These include both positive and negative values
#
LinearAlgebra:-Eigenvalues( Matrix(eval(H, S2), shape=symmetric) );

Vector(2, {(1) = -22.667008848410028, (2) = 17.91700899241002})

 

Download saddle_extr.mw

See the Help page for Topic object,function_mechanism which discusses some special situations of invoking methods.

Your process example in particular (a collision with another module in the namespace) can also be handled via the function syntax.

This might also assist you with a releated case which you have not yet covered in your Questions, involving mapping the same name (of method functions) across multiple objects. (See examples in the page.) In that case you might specifically want to not refer to the name as the export of any particular one of the objects.

restart;

module car_class()
      option object;
      local name::string:="";

      export process::static := proc(o::car_class)
             print("process method");             
      end proc:   

      export set_name::static := proc(o::car_class,_name::string)
             print("inside set name");
             o:-name := _name:
      end proc:     
end module:

my_car:=Object(car_class):  #make object

set_name(my_car,"toyota"):

"inside set name"

function:-process(my_car):

"process method"

set_name(my_car,"toyota"):

"inside set name"

 

Download object_function.mw

You could adjust the datatype to also include a specified default fill value.

Or you could specify a dummy instance of your object as a default fill value -- even if the fill value never gets used explicitly.

As an example of the former idea:

restart;
module solution_class()
      option object;
      local sol::anything;
end module:

sol:=Object(solution_class):

A := Array(datatype={solution_class,identical(NULL)}, fill=NULL):

A(1) := sol;

Vector(1, {(1) = module solution_class () local sol::anything; option object; end module})

 

Download Array_dt_fill.mw

The former idea looks a little uglier when set up, and interferes a little as it relaxes the strictures that usually come for free from a proscriptive datatype. But the latter idea could be unsatisfactory if you really didn't want any instance to exist strictly outside of when instances were stored. (Such a circumstance could be contrived, albeit artificial.)

Also, the awkwardness is not specific to object types.

Array(datatype=prime);
Error, unable to store '0' when datatype=prime

A:=Array(datatype=prime, fill=2):  # distasteful
A(3):=7;  # ugh
             A := [2, 2, 7]

A:=Array(datatype=prime, storage=sparse):
A(3):=7;  # sigh
Error, unable to store '0' when datatype=prime

A:=Array(datatype={prime,identical(0)}, storage=sparse):
A(3):=7;
             A := [0, 0, 7]

@nm You wrote,

   "It would be much more natural to do something like
     my_car[set_name]("toyota") or my_car:-set_name("toyota")

    And then my_car:-get_name() since in these, the object itself
    is upfront, instead of being passed as an argument."

You can do this:

restart;

module car_class()
      option object;
      local name::static;  #private
      export set_name::static:=proc(nname::string)
          name := nname;
      end proc;
      export get_name::static:=proc()
          return name;
      end proc;      
end module:

my_car:=Object(car_class); #make an object of class car

module car_class () option object; end module

my_car:-set_name("toyota"):

my_car:-get_name();

"toyota"

 

Download car_class.mw

Of the 8 root formulas (in v[c]) there are two that are real-valued for all real b[2].

You could plot them using the implicitplot command. Or you could plot the explicit formulations of just those two. Or you could plot the real and imaginarty parts of the explicit forumulations. You could investigate the discriminant, if you so wish.

What makes you think that you are missing out on some details? I see no evidence that you're missing out of some regions of b[2] for which there are additional nontrivial purely real solutions. Did I miss it?

note. I don't advise trying to think of matching up the explicit formulas (or their real and imaginary components) with particular connect curves, unless you want to wade into deeper water. (This relates to the blue vertical noice connecting curves in two of the plots.)

note. I have not tried to do anything along the lines of RootFinding:-Parametric, even with an approximation for Pi.

restart;

expr:=(-6*v^8*b[1]+(36*b[1]^2-12*b[2])*v^6-24*v^4*b[1]*b[2]+56*Pi*v^2+240*Pi*b[1])/(Pi*v^10*(v^2+6*b[1]));

(-6*v^8*b[1]+(36*b[1]^2-12*b[2])*v^6-24*v^4*b[1]*b[2]+56*Pi*v^2+240*Pi*b[1])/(Pi*v^10*(v^2+6*b[1]))

# I need to solve this polynomial and look at how the solutions behave over different values of b[2]

P:=eval(-numer(expr),[b[1]=1]);

6*v^8+12*v^6*b[2]-36*v^6+24*v^4*b[2]-56*Pi*v^2-240*Pi

discrim(P, v); factor(%);
[solve(%<0)];
evalf(%);

-72138957898383360*Pi^3*(-2744*Pi^2*b[2]^3+49632*Pi*b[2]^4-4320*b[2]^5+28224*Pi^2*b[2]^2-952800*Pi*b[2]^3+43200*b[2]^4+21609*Pi^3-451332*Pi^2*b[2]+5694948*Pi*b[2]^2-38880*b[2]^3+3537108*Pi^2-10760040*Pi*b[2]+5904900*Pi)^2

-72138957898383360*Pi^3*(-18*b[2]+162+Pi)^2*(-2744*Pi*b[2]^3+240*b[2]^4+28224*Pi*b[2]^2-240*b[2]^3+21609*Pi^2-62370*Pi*b[2]+36450*Pi)^2

[RealRange(-infinity, Open(9+(1/18)*Pi)), RealRange(Open(9+(1/18)*Pi), Open(RootOf(240*_Z^4+(-2744*Pi-240)*_Z^3+28224*Pi*_Z^2-62370*Pi*_Z+21609*Pi^2+36450*Pi, index = 1))), RealRange(Open(RootOf(240*_Z^4+(-2744*Pi-240)*_Z^3+28224*Pi*_Z^2-62370*Pi*_Z+21609*Pi^2+36450*Pi, index = 1)), Open(RootOf(240*_Z^4+(-2744*Pi-240)*_Z^3+28224*Pi*_Z^2-62370*Pi*_Z+21609*Pi^2+36450*Pi, index = 2))), RealRange(Open(RootOf(240*_Z^4+(-2744*Pi-240)*_Z^3+28224*Pi*_Z^2-62370*Pi*_Z+21609*Pi^2+36450*Pi, index = 2)), infinity)]

[RealRange(-infinity, Open(9.174532925)), RealRange(Open(9.174532925), Open(13.54833498)), RealRange(Open(13.54833498), Open(21.09299752)), RealRange(Open(21.09299752), infinity)]

plots:-implicitplot(P, b[2]=-15..22, v=-10..10, gridrefine=3);

HHH := simplify([solve(P,v,explicit)]):
nops(HHH);

8

plots:-display(
  seq(plot([Re,Im](HHH[i]), b[2]=-15..22), i=1..2)
);

plots:-display(
  seq(plot([Re,Im](HHH[i]), b[2]=-15..22), i=1..8)
);

HH := [solve(P,v)]:

HH1 := [allvalues(HH[1])]:
HH2 := [allvalues(HH[2])]:

plots:-display(
  plot(HH1[1], b[2]=-15..22),
  plot(HH2[1], b[2]=-15..22)
);

seq( print(evalf[20](eval(simplify(HH1[i]), b[2]=10))), i=1..4 );

1.2758485664478996255+0.97939797510404682722e-21*I

0.70362672524111679003e-20+1.4345487083972181802*I

0.28516187852517728599e-20-1.9661192724546546340*I

0.18415764139723627810e-20-3.1151620462225417219*I

plots:-display(
  seq(plot([Re,Im](HH1[i]), b[2]=-15..22), i=1..4),
  seq(plot([Re,Im](HH2[i]), b[2]=-15..22), i=1..4)
);

 

Download ComplexPlotQuestion_ac.mw

restart

with(plots); with(plottools)

interface(imaginaryunit = I)

L := `~`[[Re, Im]](sort([fsolve(x^8-1-I, x, complex)], key = argument))

display(pointplot(L, symbol = solidcircle, symbolsize = 20, color = red), polygon(L, style = line, thickness = 2, color = blue), gridlines)

NULL

Download ComplexQuestion_ac.mw

First 120 121 122 123 124 125 126 Last Page 122 of 336