acer

19487 Reputation

29 Badges

14 years, 314 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The authors of the package have stated steps here:
     https://www-polsys.lip6.fr/~jcf/FGb/FGb/x86_64_linux/index.html

Did you follow those steps?

(By the way, how do you think that relates to the version that is bundled in Maple 2020? Are you look for that site's specific version because of instructions for compatibility with another 3rd party package? It might help more if you described the full background of the query.)

The following can process 10^5 entries (sub-sets of set A) in about 1 second on my machine.

On my machine this was about 20% faster than mapping convert,string for 10^5 entries.

But for 100 entries I don't think that you'd be able to distinguish the difference.

restart;
A:={{"1","8"},{"1","4"},{"1","10"}};
           A := {{"1", "10"}, {"1", "4"}, {"1", "8"}}

map[2](sprintf,"%a",A);
          {"{"1", "10"}", "{"1", "4"}", "{"1", "8"}"}

An alternative but shorter syntax is,

sprintf~("%a",A);

You have made a common mistake in 2D Input syntax. Your two bracketed terms inside the sqrt are not being multiplied together. They are parsed together as a compound function call.

To get what you intended you can either insert an explicit multiplication sign or (in 2D Input mode) insert a space to denote mutiplication implicitly.

NULLassume(0 < k, k < 1)

int(x^2/sqrt((-x^2+1)*(-k^2*x^2+1)), x = 0 .. k)

EllipticF(k, k)/k^2-EllipticE(k, k)/k^2

``

Download ellipticIntegralTest_ac.mw

 

Could you make big_car itself an object, and pass that to the method procedure, etc?

[edited] I didn't really understand why you want big_car:-set_name declared as static, btw, given the rest of your example's structure and the original description you gave. But you could also change this code below so that big_car_name was instead declared as static(string).

restart;

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

      export set_name::static:=proc(o::car_class,_name::string)
        o:-name := _name;
        o:-big_car:-set_name(o:-big_car,_name);
      end proc;

      #this is module, that I want to be private to this class only
      #eventually, I'd like this module be in separate mpl file also.
      local big_car::static :=module()  #module does not take arguments!
            option object;
            #this below should be private only to the this module
            #and not seen by the enclosing object.
            local big_car_name::string:="UNKNOWN";  

            #this export to allow parent object to call it
            export set_name::static:=proc(o::big_car,_name::string)
                   o:-big_car_name:=_name;
            end proc;

      end module;

end module:

o:=Object(car_class);

module car_class () local name::string; option object; end module

o:-set_name(o,"GM");

"GM"

# As desired, car_class does not export big_car .
#
o:-big_car:-set_name(o,"Ford");

Error, module `car_class` does not export `big_car`

 

Download object_submodule.mw

It's unclear what you mean by stating that you want big_car defined in its own .mpl file, if you want it declared as a (static) local of the car_class object. Do you just mean that the source of the car_class will $include the source of big_car?

Your first example contained the code snippet,
    big_car:-set_name("toyota")
which you claimed did set the name for your first variant. Is that incomplete and a typo, or actually what you meant? (I have guessed at the intended meaning to be that the car_class object would not export from submodule big_car literally/directly.)

One thing you should know is that the product 14*(7 - 2*sqrt(7)) will automatically simplify to 98-28*sqrt(7), and that cannot be prevented merely by delaying evaluation.

There are a few ways to represent that product so that it prettyprints nicely, and so that you can recover the actual value for further computation.

Here, I'll use the inert `&*` operator instead of the usual active `*`. By default that will prettyprint with a gray multiplication symbol. You can also use the InertForm:-Display command to make it prettyprint in the more usual way.

restart;

'14*(7 - 2*sqrt(7))';

98-28*sqrt(7)

ee := 98-28*sqrt(7);

98-28*7^(1/2)

new := `%*`(content(98-28*sqrt(7), sqrt(7)),
            primpart(98-28*sqrt(7), sqrt(7)));

`%*`(14, 7-2*7^(1/2))

value(new);

98-28*7^(1/2)

InertForm:-Display(new, inert=false);

0, "%1 is not a command in the %2 package", _Hold, Typesetting

 

Download auto_simp.mw

I will also mention that the alternative mechanism (to prevent actual multiplication) of using the ``(...) call will make the result prettyprint with round brackets even if that part is not a sum of terms.

You might also consider the following, though we do not know what other kinds of examples you might have.

content(98/3-28/3*sqrt(7), sqrt(7));
                               14
                               --
                               3 

icontent(98/3-28/3*sqrt(7));
                               14
                               --
                               3 

Also, if you are going to use these mechanisms programmatically then you might want to have a special case that primpart returns 1 or -1 (so that it doesn't print with unnecessary clutter). Again, we don't know what other kinds of examples you might have.

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

5 6 7 8 9 10 11 Last Page 7 of 222