acer

32333 Reputation

29 Badges

19 years, 325 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You do not need to assign to the varuable names v1,v2,etc which would have the drawback that you'd need to unassign them in order to re-use then conveniently as names. You can accomplish the same effects using a list of equations or a table, either of which can be used to associate the names with the values.

This is a common and important usage scenario in Maple.

restart;

List1 := [v1,v2,v3,v4];

[v1, v2, v3, v4]

List2 := [a*b/c, a/c,a*b-2,d];

[a*b/c, a/c, a*b-2, d]

R := Equate(List1,List2);

[v1 = a*b/c, v2 = a/c, v3 = a*b-2, v4 = d]

expr := sin(x*y);

sin(x*y)

f := a*diff(expr,x)+b*diff(expr,y)+ a*b:

eval(f, [a=v1,b=v2]);

v1*y*cos(x*y)+v2*x*cos(x*y)+v1*v2

eval(f, eval([a=v1,b=v3],R));

a*b*y*cos(x*y)/c+(a*b-2)*x*cos(x*y)+a*b*(a*b-2)/c

eval(f, eval([a=v4,b=v2],R));

d*y*cos(x*y)+a*x*cos(x*y)/c+d*a/c

T:=table(R);

table( [( v4 ) = d, ( v3 ) = a*b-2, ( v2 ) = a/c, ( v1 ) = a*b/c ] )

eval(f, [a=T[v1],b=T[v3]]);

a*b*y*cos(x*y)/c+(a*b-2)*x*cos(x*y)+a*b*(a*b-2)/c

eval(f, [a=T[v4],b=T[v2]]);

d*y*cos(x*y)+a*x*cos(x*y)/c+d*a/c

func := unapply(f, [a,b]);

proc (a, b) options operator, arrow; a*y*cos(x*y)+b*x*cos(x*y)+b*a end proc

func(v1,v3);

v1*y*cos(x*y)+v3*x*cos(x*y)+v3*v1

func(T[v1],T[v3]);

a*b*y*cos(x*y)/c+(a*b-2)*x*cos(x*y)+a*b*(a*b-2)/c

func(T[v4],T[v2]);

d*y*cos(x*y)+a*x*cos(x*y)/c+d*a/c

 

Download funcsubs.mw

The leading term is determined lexicographically (here, alphabetically, but where lower/uppercase matters).

And so what matters for -v1+a is the coefficient of a , while what matters for -V1+a is the coefficient of V1.  The capital letters are taken first.

Maple needs to use some convention in your usage case where no variable list is supplied as additonal argument. It might make sense (albeit tiresomely) to complain about the particular convention used, but it would make no sense to complain that it has to have some convention.

[edit] I should point out that for important efficiency concerns Maple stores only one instance of a polynomial in memory, regardless of whether it is entered as -v1+a or later as a-v1 . Moreover a polynomial can have its subterms sorted inplace in memory, but that structural change should not affect the result from sign which is mathematical. Therefore its leading term cannot be determined by the order in which you later re-type it or the order in which the subterms are stored in memory. So a convention that considers the leading term lexicographically lets things work.

restart;
p := -V1 + a;
                          p := -V1 + a

sign(p);
                               -1

sort(p,order=plex(V1,a),ascending);
                             a - V1

p;
                             a - V1

sign(p);
                               -1

sort(p,order=plex(V1,a),descending);
                            -V1 + a

p;
                            -V1 + a

sign(p);
                               -1

Since Maple 15 it is even easier to set the default unit for a particular dimension with the UseUnit command. I mean easier than having to use the commands AddSystem and UseSystem as you did above.

This allows other scales of power to be simplified to your desired kWh/day.

You can utilize it with or without loading Units:-Standard, depending on whether you want arithmetic with units to resolve/combine automatically. Or in recent versions you can utilize it alongside Units:-Simple, which does that automatic combining of units while also allow mixed arithmetic of quantities with units attached and unknown quantities (eg. names) without units specified.

restart;

kernelopts(version);

`Maple 2018.0, X86 64 LINUX, Mar 9 2018, Build ID 1298750`

Units:-UseUnit(kWh/day):

expr1 := 4.9*Unit(kW)*3.5*Unit(h/day);

17.15*Units:-Unit(kW)*Units:-Unit(h/d)

combine(expr1, units); # no change, as desired

17.15*Units:-Unit(kWh/d)

expr2 := 1700.1*Unit(W);

1700.1*Units:-Unit(W)

combine(expr2, units);

40.80240000*Units:-Unit(kWh/d)

simplify(expr2);

40.80240000*Units:-Unit(kWh/d)

restart;

Units:-UseUnit(kWh/day):

with(Units:-Standard):

4.9*Unit(kW)*3.5*Unit(h/day);

17.15*Units:-Unit(kWh/d)

simplify(1700.1*Unit(W));

40.80240000*Units:-Unit(kWh/d)

1700.1*Unit(W)*3.4*Unit(days/week);

19.81830857*Units:-Unit(kWh/d)

restart;

Units:-UseUnit(kWh/day):

with(Units:-Simple):

4.9*Unit(kW)*3.5*Unit(h/day) + x;

17.15*Units:-Unit(kWh/d)+x

simplify(1700.1*Unit(W) - u);

1700.1*Units:-Unit(W)-u

1700.1*Unit(W)*3.4*Unit(days/week) + 40.5*k;

19.81830857*Units:-Unit(kWh/d)+40.5*k

 

Download useunit.mw

There are also facilities for right-click units re-formatting in the Maple 2018 GUI. You can also use that (or convert(...,units,W) ) to force display in Watts alone.

@primogen Have you tried,

Physics:-diff~(SimplifiedMassMatrixDot, theta[2](t));

a_ac.mw

I toggled this Question to be marked as "Maple 2017", since that's the release in which your attachment was last saved. (You had it as "Maple 17" which is four major releases earlier.)

I don't know of any easy way to handle 2D Input of units (ie. typeset via command-completion, or from the Units palette).

The following affects 2D Output. (I doubt it will work alongside right-click unit-formatting.)

restart;

kernelopts(version);

`Maple 2018.1, X86 64 LINUX, Jun 8 2018, Build ID 1321769`

 

Unit(88*kg*m/s^2) + Unit(g)*Unit(-3*cm/s^2);

88*Units:-Unit(kg*m/s^2)-3*Units:-Unit(g)*Units:-Unit(cm/s^2)

 

ChangeUnitsColor:=proc(c, {bold::truefalse:=false})
  global `print/Unit`;
  local hexstr;
  uses ColorTools;
  if c = ':-default' then
    `print/Unit`:='`print/Unit`';
    return NULL;
  end if;
  hexstr:=RGB24ToHex(RGBToRGB24([ColorTools:-Color(c)[]]));
  `print/Unit`:=subs(__dummy=hexstr,
      proc(x)
      local r;
      uses T=Typesetting;
      if interface(':-prettyprint')<2 then
        return Units:-Unit(args);
      end if;
      r:=subsindets(T:-Typeset(x),
                    ':-specfunc'({T:-mrow,T:-mi,T:-mo,
                                  T:-mfrac,T:-msup,T:-msqrt}),
                    u->op(0,u)(op(u),
                               "mathcolor"=__dummy));
      r:=subsindets(r,specfunc({T:-mi,T:-mo}),
                    u->T:-mtext(op(u)));
      if bold=true then
        r:=T:-mstyle(r, 'italic'="false", ':-fontweight'="bold");
      end if;
      return r;
    end proc);
  NULL;
end proc:

 

ChangeUnitsColor("Red");

Unit(kg^(1/2));

Units:-Unit(kg^(1/2))

Unit(s/m)+Unit(day/cm);

Units:-Unit(s/m)+Units:-Unit(d/cm)

simplify(Unit(s/m)+Unit(day/cm));

8640001*Units:-Unit(s/m)

ChangeUnitsColor("Green");

sin(x)*Unit(8.8*kg*m/s^2) + Unit(g)*Unit(-3*cm/s^2);

8.8*sin(x)*Units:-Unit(kg*m/s^2)-3*Units:-Unit(g)*Units:-Unit(cm/s^2)

combine(%, units);

(8.8*sin(x)-3/100000)*Units:-Unit(N)

ChangeUnitsColor("Blue", bold);

sin(x)*Unit(8.8*kg*m/s^2) + Unit(-3*g*cm/s^2);

8.8*sin(x)*Units:-Unit(kg*m/s^2)-3*Units:-Unit(g*cm/s^2)

Unit(43*'kg'^2)

43*Units:-Unit(kg^2)

ChangeUnitsColor(default);

sin(x)*Unit(8.8*kg*m/s^2) + Unit(g)*Unit(-3*cm/s^2);

8.8*sin(x)*Units:-Unit(kg*m/s^2)-3*Units:-Unit(g)*Units:-Unit(cm/s^2)

``

Download unitcolorbold.mw

restart;

g := x -> (2*x-7)^('-3');

proc (x) options operator, arrow; (2*x-7)^'-3' end proc

new := InertForm:-MakeInert(g(x)):

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

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

g(6);

1/125

other := subs(x=6, new):

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

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

value(other);

1/125

map[2](op,2,indets(g(x), `^`));

{-3}

-degree(denom(g(x)),x);

-3

 

Download inertanother.mw

restart;

kernelopts(version);

`Maple 2018.1, X86 64 LINUX, Jun 8 2018, Build ID 1321769`

assume(x>0);

expr := sqrt(x^3*x^(3/4));

(x^(15/4))^(1/2)

new := combine(expr);

x^(15/8)

map[2](op,2,indets(new,identical(x)^anything));

{15/8}

restart;

expr := surd(a*'surd'(a*a^b,2),4);

surd(a*surd(a*a^b, 2), 4)

inertexpr := InertForm:-MakeInert(eval(expr,1)):

new := subs([a=2,b=6,c=4], inertexpr):

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

Typesetting:-mcomplete(Typesetting:-mroot(Typesetting:-mcomplete(Typesetting:-mrow(Typesetting:-mn("2"), Typesetting:-mo("&sdot;"), Typesetting:-mcomplete(Typesetting:-mroot(Typesetting:-mcomplete(Typesetting:-mrow(Typesetting:-mn("2"), Typesetting:-mo("&sdot;"), Typesetting:-mcomplete(Typesetting:-msup(Typesetting:-mrow(Typesetting:-mn("2")), Typesetting:-mn("6"), Typesetting:-msemantics = "^"), Typesetting:-_Hold([`%^`(2, 6)]))), Typesetting:-_Hold([`%*`(2, `%^`(2, 6))])), Typesetting:-mn("2")), Typesetting:-_Hold([%surd(`%*`(2, `%^`(2, 6)), 2)]))), Typesetting:-_Hold([`%*`(2, %surd(`%*`(2, `%^`(2, 6)), 2))])), Typesetting:-mn("4")), Typesetting:-_Hold([%surd(`%*`(2, %surd(`%*`(2, `%^`(2, 6)), 2)), 4)]))

InertForm:-Value(new);

2*2^(1/8)

 

Download inertsurd.mw

The multiple assignment functionality was added in Maple V R5 which was released in 1997.

Have you tried,

display(Array([ display(A,B), C ]));

More importantly, Shouldn't you call it like,

Explore( P(a), parameters=[a=-1.0..1.0] );

so that it explores a function call to P?

Yes, you should be to accomplish this using Embedded Components, as long as the data exists before the plotting begins.

If you're hoping for an asynchronous process that sits there waiting for newly computed data points to be added to the file then the task is much more complicated (if possible at all).

Do you have a sample of data? What kind of plot do you want?

You can map the diff command over the Matrix.

step1calshelper_ac.mw

I also show various simplifications (and their effects on the size of the Matrix entries).

Make a Matrix with the two lists as its columns (ie. column Vectors).

A := [[0, 1, 2, 3, 4, 5], [0, 2, 4, 6, 8, 10]]:
M:=<<A[1]>|<A[2]>>:
ExportMatrix(test, M, delimiter=" "):

Alternatively, create the Matrix with the lists as the rows, and export its transpose.

A := [[0, 1, 2, 3, 4, 5], [0, 2, 4, 6, 8, 10]]:
M:=Matrix(A):
ExportMatrix(test, M^%T, delimiter=" "):

It cannot be done straight from Maple, AFAIK.

It would be interesting if someone proved me wrong by showing a way using the Maple's HTTP or URL (or lower level via Sockets). Its not clear to me how login or authentification might work.

It'd be trickier still, since uploads to Mapleprimes are attachments to posts. It might be more effort to upload without a post (and then somehow post separately and attach the prior raw upload) or to effect both directly from Maple.

Upload and insertion of a link to the worksheet, or inlining of the worksheet, is available from within Mapleprimes using the green up-arrow that appears in the menubar of the Question/Reply/Post editor.

Upload to the Maplecloud is possible, directly from Maple. But I'm not aware that Mapleprimes and the Maplecloud have any functional interchange.

The easiest way is to put both subpackages within a single parent package.

If you really want them distinct then you can utilize an abbreviation scheme. Here are two choices for that:

1) Utilize the $define preprocessor directive in the source. (I prefer to load all my packages from source code stored in plaintext files outside of any worksheet.) For example,

$define OPFCN OriginalPackage:-Function

# alternatively
$define OP OriginalPackage
$define FCN Function

The second of those would be utilized by accessing OP:-FCN in the subsequent code.

At the end of the source file you can utilize the corresponding $undef directives.

2) Utilize the uses syntax at the start of the source for each procedure in the dependent (2nd) package. For example,

NewFunction := proc(x)
  local blah,blech;
  uses OP=OriginalPackage,
       OPFCN=OriginalPackage:-Function;

  blah := OP:-OtherFunction(x);
  blech := OPFCN(blah*x);
end proc;

If the whole equation is assigned to the name eqn , then how about,

collect( expand(lhs(eqn)), Rm, simplify ) = rhs(eqn);
First 170 171 172 173 174 175 176 Last Page 172 of 336