acer

32328 Reputation

29 Badges

19 years, 318 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

After you have executed a Document Block, select all of it, both input and output. (You can use the mouse pointer to left-click & drag, or Ctl-Alt-Shift-D, or right-click in the border if your have the Markers visible.)

Then use the menubar item,
   Edit -> Document Blocks -> Toggle Input/Output display

That allows you to hide the input of a particular Document Block (as opposed to, say, all input in the sheet).

It's a little awkward to undo the effect, though you should be able to use the "Show Command" item from the same submenu.

That works for me in Maple 2019 without having to encapsulate in a Table (which has its own mechanism for this kind of thing). 

[edit: presumably you have some other examples to cover, with some general action, or else you could just square both sides, trivially...]

How do you feel about using the isolate command here?

restart;

eq:=sqrt(y)=tanh(x):

isolate(eq,y);

                           2
                y = tanh(x) 

Or perhaps you might be able to get by with temporarily substituting or freezing the trigh terms (but be more careful if you need to preserve the explicit dependence on name x, for subsequent or intermediate differentiation, say).

thaw(solve(subsindets(eq,trigh,u->freeze(u)),y));

There is quite often a balance between terse syntax and higher performance. By this I mean the contrast of short syntax against rewriting such operations in just one or two (evalhf'able or Compile'able) procedures that are verbose but very efficient in memory and computation time.

But here are some ideas. (I used Maple 2015, on Linux.)

I found it interesting that the original elementwise action of pi0 and pi1 on float[8] Vector Q would not produce a float[8] result. So I forced that -- saving some time and memory -- by using map[evalhf] instead, for which I had to reverse the order of their parameters. (Sometimes such a result does attain, with a builtin action, say. But not this pi0 & pi1.)

I have stopped well short of rewriting everything (except the Sample calls) in one  big evalhf'able/Compile'able procedure. There can be diminishing returns in such effort.

restart:

pi0 := (p, n) -> (1-p)^n:

pi1 := (p, n) -> n*(1-p)^(n-1) * p:

f4 := proc(REP, a, b, N)

  local Q, P0, P1, P01, U, Got01, Got0, N01, N0, N1:
 uses ST=Statistics, LA=LinearAlgebra:

  Q     := ST:-Sample(Uniform(a, b), REP):

  P0    := map[evalhf](pi0, Q, N):

  P1    := map[evalhf,inplace](pi1, Q, N):

  P01   := LA:-VectorAdd(P1,P0,inplace):

  U     := ST:-Sample(Uniform(0, 1), REP):

  N01   := add(`<=`~(U-P01,0)):

  N0    := add(`<=`~(U-P0,0)):

  N1    := N01-N0:

  N0, N1;

end proc:

CodeTools:-Usage(f4(10^5, 0, 5e-4, 25000), iterations=5);

 

memory used=24.07MiB, alloc change=44.49MiB, cpu time=132.80ms, real time=133.40ms, gc time=9.87ms

HFloat(7917.0), HFloat(8013.0)

pi0 := (p, n) -> (1-p)^n:

pi1 := (p, n) -> n*(1-p)^(n-1) * p:

f4a := proc(REP, a, b, N)

  local Q, P0, P1, P01, U, Got01, Got0, N01, N0, N1:
 uses ST=Statistics, LA=LinearAlgebra:

  Q     := ST:-Sample(Uniform(a, b), REP):

  P0    := map[evalhf](pi0, Q, N):

  P1    := map[evalhf](pi1, Q, N):

  LA:-VectorAdd(P1,P0,inplace):

  ST:-Sample(Uniform(0, 1), Q):

  N01   := add(`<=`~(Q-P1,0)):

  N0    := add(`<=`~(Q-P0,0)):

  N1    := N01-N0:

  N0, N1;

end proc:

CodeTools:-Usage(f4a(10^5, 0, 5e-4, 25000), iterations=5);

 

memory used=23.68MiB, alloc change=0 bytes, cpu time=123.00ms, real time=123.20ms, gc time=8.35ms

HFloat(8110.0), HFloat(7962.0)

shazam := proc(V1::Vector(datatype=float[8]),
               V2::Vector(datatype=float[8]),
               N::integer) local c::integer,i::integer;
  c := 0;
  for i from 1 to N do
    if V1[i] <= V2[i] then c := c+1; end if;
  end do;
  return c;
end proc:
try
  cshazam := Compiler:-Compile(shazam);
catch:
error;
  cshazam := (V1,V2,NN)->evalhf(shazam(V1,V2,NN));
end try:

f5 := proc(REP, a, b, N)

  local Q, P0, P1, P01, U, Got01, Got0, N01, N0, N1:
  uses ST=Statistics, LA=LinearAlgebra:

  Q     := ST:-Sample(Uniform(a, b), REP):

  P0    := map[evalhf](pi0, Q, N):

  P1    := map[evalhf,inplace](pi1, Q, N):

  P1    := LA:-VectorAdd(P1,P0,inplace):

  U     := ST:-Sample(Uniform(0, 1), REP):
  N01   := cshazam(U, P1, REP);
  N0    := cshazam(U, P0, REP);

  N1    := N01-N0:

  N0, N1;

end proc:

 

CodeTools:-Usage(f5(10^5, 0, 5e-4, 25000), iterations=5);

 

 

memory used=14.53MiB, alloc change=0 bytes, cpu time=78.80ms, real time=79.00ms, gc time=8.34ms

8054, 8179

 

Download MakeItFaster_ac.mw

If you have to repeat the whole computation several times, then the "memory used" number can have more effect (because it alludes to how much memory management is going on). Lower is better, even if the wall-clock timing is otherwise the same for a run. I used some in-place operations, to reduce production of collectible garbage within the procedure. There are several choices in how to go about that. But I didn't do a variant where Q is reused as the third argument to Sample, etc. Refactoring the code to use the fewest number of separate Vectors is another diminishing return, and can forsake readability.

 

There are several mistakes.

The syntax mistakes mostly relate to plot, assignment, etc, rather than to the Explore command.

You forgot the colon in the assignment syntax, for P, and so didn't actually assign to anything.

The syntax for the plotting command is strangely wrong. (Is this a cut&paste of something else?!)

It's difficult to guess what you mean by the data values for plotting. Which are the independent values? What is ()...() supposed to mean?

You forgot to assign any numeric values to M_0, M_1, k_0, and k_1.

You appear to have shown us something like an invalid plaintext version of some 2D Input. That's no good. Upload your actual worksheet, instead of doing that.

I can guess what sort of thing you intended for the data. I made a short guess. The following works, and you should be able to fill in the missing data. (If not, then upload your worksheet.)

explore_plot.mw

With a call to Table (from DocumentTools:-Layout) you can pass calls to Column (same package) and specify the `weight` option.

It takes as many Column calls as there are columns (counting span). The weights are relative to each other.

Let us know if that's not your context.

You can get the comparison using Units:-Simple instead of Units:-Standard, although zero meters is still just zero.

restart

with(Units:-Simple)

a := 15*Unit('m')

15*Units:-Unit(m)

b := 13000*Unit('mm')

13000*Units:-Unit(mm)

min(a, b)

13*Units:-Unit(m)

c := 0*Unit('m')

0

min(a, c)

0

NULL

Download UnitsStandardCompare_ac.mw

[edited] I've deleted my answer using the CenterOfMass command, as I overlooked the coordinate system and made an unfortunate choice for the integration bounds (related to the square).

Tom's done it in his own Answer, now.

Let me know if this is close to what you are after (or if it needs adjustment).

restart;

F:=proc(p::polynom(anything,x), n) local d;
  d := degree(p,x);
  if n<=d then
    error "n=%1 is not greater than degree=%2 of polynomial in x",n,d;
  end if;
  Matrix(n-d,n,'scan'=':-band'[0,d],
         [seq([coeff(p,x,i)$(n-d)],i=0..d)]);
end proc:

F(x^4+3*x^3+x^2+2*x+1, 10);

_rtable[18446883698950820438]

F(x^5+11*x^2-3*x, 10);

_rtable[18446883698955243518]

F(x^5+11*x^2-3*x, 5);

Error, (in F) n=5 is not greater than degree=5 of polynomial in x

F(x^5+11*x^2-3*x, 6);

_rtable[18446883698955249894]

F(x^5+11*x^2-3*x, 8);

_rtable[18446883698955250974]

 

Download mat_polycoeff.mw

Perhaps this will help. (I'm not sure whether it is good for your purposes...)

restart

with(XMLTools)

xmltree := XMLElement("database", ["version" = "test"])

_XML_Element(_XML_ElementType("database"), [_XML_Attribute(_XML_AttrName("version"), _XML_AttrValue("test"))], [])

xmlmaterial := XMLElement("materials")

_XML_Element(_XML_ElementType("materials"), [], [])

xmltree := AddChild(xmltree, xmlmaterial, 0)

_XML_Element(_XML_ElementType("database"), [_XML_Attribute(_XML_AttrName("version"), _XML_AttrValue("test"))], [_XML_Element(_XML_ElementType("materials"), [], [])])

 

HasChild(xmltree, XMLElement("materials"))

true

xmldoc := XMLDocument(xmltree); xmldocA := subsindets(xmldoc, function, proc (s) options operator, arrow; setattribute(s, ':-inert') end proc)

_XML_Document(_XML_Element(_XML_ElementType("database"), [_XML_Attribute(_XML_AttrName("version"), _XML_AttrValue("test"))], [_XML_Element(_XML_ElementType("materials"), [], [])]))

 

readxmltree := ParseString(ToString(xmltree)); readxmltreeA := subsindets(readxmltree, function, proc (s) options operator, arrow; setattribute(s, ':-inert') end proc)

_XML_Document(_XML_Element(_XML_ElementType("database"), [_XML_Attribute(_XML_AttrName("version"), _XML_AttrValue("test"))], [_XML_Element(_XML_ElementType("materials"), [], [])]))

NULL

HasChild(xmldocA, XMLElement("materials"))

true

``

FirstChild(xmldocA)

_XML_Element(_XML_ElementType("materials"), [], [])

HasChild(readxmltreeA, XMLElement("materials"))

true

FirstChild(readxmltreeA)

_XML_Element(_XML_ElementType("materials"), [], [])

``

Download HasChild_ac.mw

Here is one way,

restart;

PMSM_v_eq := V__alphabeta(t) = R__s * i__alphabeta(t)
                               + L__s*diff(i__alphabeta(t), t)
                               + diff(lambda__alphabeta(t), t);

V__alphabeta(t) = R__s*i__alphabeta(t)+L__s*(diff(i__alphabeta(t), t))+diff(lambda__alphabeta(t), t)

eq_desired := lambda__alphabeta(t) = int(V__alphabeta(t) - R__s * i__alphabeta(t), t)
                                     - L__s*i__alphabeta(t);

lambda__alphabeta(t) = int(V__alphabeta(t)-R__s*i__alphabeta(t), t)-L__s*i__alphabeta(t)

with(IntegrationTools):

Combine(value(Expand(dsolve(PMSM_v_eq, {lambda__alphabeta(t)}))));

lambda__alphabeta(t) = int(V__alphabeta(t)-R__s*i__alphabeta(t), t)-L__s*i__alphabeta(t)+_C1

evalindets(%,suffixed(_C),()->0);

lambda__alphabeta(t) = int(V__alphabeta(t)-R__s*i__alphabeta(t), t)-L__s*i__alphabeta(t)

 

Download PMSM_eq_ac.mw

[edit] The following is shorter (only because it avoids having to dispel the constant of integration), but it seems slightly odd (to me) to ignore the dsolve command entirely.

IntegrationTools:-Combine(solve(value(map(int,PMSM_v_eq,t)),
                                {lambda__alphabeta(t)})[]);

It's not clear from your question how you want to treat multiple (or nested) solutions coming out of solve, as your only example is simple. I could guess...

sol:={v[1]=t,v[2]=3/2*t,v[3]=v[3]};

{v[1] = t, v[2] = (3/2)*t, v[3] = v[3]}

subsindets(sol,And(`=`,':-satisfies'(s->(lhs=rhs)(s))),()->NULL);

{v[1] = t, v[2] = (3/2)*t}

Download solve_removal.mw

@coopersj The default behaviour of the 2D Input  ||V||  should match the current context's behaviour of Norm(V) , in the case where neither explicitly specifies a particular norm.

Of course, each should always be available -- if provided explicitly -- so as to clarify the situation if the nature of the worksheet's material and content make the context non-obvious. And so they are. I used command-completion on the word "Norm" whilst in 2D Input mode, to select a specified norm from the popup menu.

restart

with(LinearAlgebra)

V := `<,>`(2, 2, 2)

Vector[column](%id = 18446883978238448574)

LinearAlgebra[Norm](V)

2

LinearAlgebra[Norm](V, 2)

2*3^(1/2)

LinearAlgebra[Norm](V, infinity)

2

restart

with(VectorCalculus)

V := `<,>`(2, 2, 2)

Vector(3, {(1) = 2, (2) = 2, (3) = 2})

LinearAlgebra[Norm](V)

2*3^(1/2)

LinearAlgebra[Norm](V, 2)

2*3^(1/2)

LinearAlgebra[Norm](V, infinity)

2

 

Download norm_LAVC.mw

One way to get the results without the x is to change how you call fsolve, ie.,

f := x^2-x+0.25:

fsolve({f=0}, x=0..1);

     {x = 0.5000000000}, {x = 0.5000000000}

[fsolve(f=0, x=0..1)];                          

         [0.5000000000, 0.5000000000]

Your first question about "storing" the results is unclear. If you assign the last result about to S then you can access each root by indexing, eg,

S := [fsolve(f=0, x=0..1)];

          S := [0.5000000000, 0.5000000000]

S[1];

                  0.5000000000

S[2];

                  0.5000000000

Under the location of my Linux installation of Maple 2020.1 there is a file (relative path):
   bin/Maple2020.png

That is a 1-layer 48x48 pixel RGB color space PNG image, at 72x72 ppi and a print size of 16.93x16.93 mm.

You could try scaling that up in size (after making a copy of the original file).

Of course, the final behavior is up to your twm window manager.

The simplest way to switch the orientation roles is to use the parametric calling sequence of the plot command.

plot([y^2, y, y = -3 .. 3],
     color=blue, thickness=3, title="T1.1 x=y^2 [ECE]",
     view=[-5..5, -5..5]);

I don't care so much for the three choices Tom mentioned. The rotate example involves more typing, a little extra computing, generates a temporary plot as collectible garbage, but is otherwise ok. Solving/inverting the expression analytically for all branches is problematic in general. And implicitplot is inefficient (compared to a direct plot).

First 104 105 106 107 108 109 110 Last Page 106 of 336