acer

32333 Reputation

29 Badges

19 years, 321 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The sort command can be used to rearrange the additive terms in some kinds of polynomial, using a flavour of monomial ordering. It works by replacing the particular expression's form that the kernel stores in its table of "uniquified" expressions (aka "simpl" table).

I can cook one up for your example, by eye. For such a monic example it'd be easy to write a procedure that does a subsindets on suitable `+` subterms -- where the action involves a scan and a sort call.

restart;


I forcibly enter the expression in the undesired form, to illustrate
that it can occur. Then I sort it. And then I show that its form has
been changed.

( - a1b2 + a2b1) * j1 + ( - a3b5 + a4b4) * j2:
a := (a2b1-a1b2)*j1+(a4b4-a3b5)*j2:

 

a;

(-a1b2+a2b1)*j1+(-a3b5+a4b4)*j2

 

sort(a, order=plex(a2b1,a4b4)):

 

a;

(a2b1-a1b2)*j1+(a4b4-a3b5)*j2

Download sort_ex.mw

But the facility is restricted. You can easily construct a more general example for which none of the available sortings would be able to achive the goal.

 

kernelopts(version)

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

restart; assume(1 <= x, x <= 4)

assume(0 < y, y < 1)

f := 1-4*(x-1)*(1+y)/(x^2*(1-y))

sols := [solve(f > 0, useassumptions)]

[{x = 1, 0 < y, y < 1}, {0 < y, 1 < x, x < 2, y < (x^2-4*x+4)/(x^2+4*x-4)}, {0 < y, 2 < x, x < 4, y < (x^2-4*x+4)/(x^2+4*x-4)}, {x = 4, 0 < y, y < 1/7}]

seq(`assuming`([is(f > 0)], [sols[i][]]), i = 1 .. nops(sols))

true, true, true, true

restart

f := 1-4*(x-1)*(1+y)/(x^2*(1-y)):

solsO := [solve({f > 0, 1 <= x, x <= 4, 0 < y, y < 1})];

[{x = 1, 0 < y, y < 1}, {0 < y, 1 < x, x < 2, y < (x^2-4*x+4)/(x^2+4*x-4)}, {0 < y, 2 < x, x < 4, y < (x^2-4*x+4)/(x^2+4*x-4)}, {x = 4, 0 < y, y < 1/7}]

seq(`assuming`([is(f > 0)], [solsO[i][]]), i = 1 .. nops(solsO));

true, true, true, true

``

Download positive_function_ac.mw

Append the string with the full location of the .mla file to libname, in Maple. For example,

   libname := libname, "C:/Users/Lisa6/Documents/myfolder/filename.mla";

You only need to do that once per session, so you could put it at the beginning of your worksheet, or right after a restart .

Note that a .mla file can contain several things. It's possible that your file blah.mla also happens to contain a module package blah, so that you can issue the with(blah); command. But the name of the things stored in your blah.mla file may be named differently.

A unit is not part of the embedded component per se.

But you can force a particular unit for a particular dimension, as a preference set with the Units:-UseUnit command. And that will get carried over to what is put inside a MathContainer. For example,

restart;

W := 87.7 * Unit(joule/m^2);

87.7*Units:-Unit(J/m^2)

combine(W, units);

87.7*Units:-Unit(kg/s^2)

V := 45.6 * Unit(kg/s^2);

45.6*Units:-Unit(kg/s^2)

Units:-UseUnit(N/m):

combine(W, units);

87.7*Units:-Unit(N/m)

combine(V, units);

45.6*Units:-Unit(N/m)

simplify(V);

45.6*Units:-Unit(N/m)

DocumentTools:-SetProperty("MathContainer0", expression, combine(V, units));

Download UseUnit_EC.mw

You can also re-express something in terms of units of compatible dimension. And that can always be done directly, without Units:-UseUnit . Again, the unit is simply a part of the expression, and not specific to the embedded component. For example,

restart;

V := 45.6 * Unit(kg/s^2);

45.6*Units:-Unit(kg/s^2)

convert(V, units, N/m);

45.6*Units:-Unit(N/m)

DocumentTools:-SetProperty("MathContainer0", expression, convert(V, units, N/m));

Download Unit_EC.mw

In either scenario above you could also produce results in terms of kN/m if you prefer. The component step would be done similarly.

restart;

V := 45.6 * Unit(kg/s^2);

45.6*Units:-Unit(kg/s^2)

convert(V, units, kN/m);

0.4560000000e-1*Units:-Unit(kN/m)

Units:-UseUnit(kN/m):

combine(V, units);

0.4560000000e-1*Units:-Unit(kN/m)

 

Download Unit_kN.mw

 

There are several ways to get such an effect.

You should be able to adjust the following easily (to alter the colors or symbolsize, include the axes, remove the blue circle, slow it down with more frames, etc). If you want help just state precisely what effects you want. Or see the Help pages for Topics like animate or plot,options .

restart;

bg := plot([sin(tt),cos(tt),tt=0..2*Pi],color="Navy",thickness=0):

G := proc(t) local tt;
  plots:-display(
    bg,
    plot([sin(tt),cos(tt),tt=0..t],color="Red",thickness=3),
    plot([[sin(t),cos(t)]],style=point,color="Red",
         symbol=solidcircle,symbolsize=30));
end proc:

plots:-animate(G, [t], t=0..2*Pi, frames=50,
               paraminfo=false, axes=none);

 

Download circle_trace.mw

I find that one of the easiest ways to start doing an animation is to contruct a procedure that produces just a single frame. Here, the procedure G can be called to show a single frame. For example,

G(Pi/4)

That makes calling plots:-animate much simpler. And it allows you to test easily the generation of any particular frame, without having to build the whole animation.

Your a and b are Matrices whose entries are Vectors.

You could consider something like these (alas, there is no andzip).

   andmap(evalb,Equal~(a,b));

   Equal~(a,b);

If you need extra efficiency -- with false return upon the first mismatch -- you could write your own.

Your first use of PDEtools[declare] makes psi(t) appear as just psi in output. But it doesn't affect input, and in your usage you'd still need to type psi(t) if you want to refer to it.

The Physics:-diff command will allow you to differentiate with respect to psi(t).

The name theta__l gets prettyprinted with an underscore. You could use another name if you'd prefer to avoid that.

restart

PDEtools[declare](`&theta;__l`(t), `&beta;__l`(t), `&theta;__si`(t), `&beta;__si`(t), psi(t), x(t), z(t)); PDEtools[declare](prime = t)

`derivatives with respect to`*t*`of functions of one variable will now be displayed with '`

V__1lx := diff(x(t), t)-(1/2)*l__b*sin(psi(t))*(diff(psi(t), t))-l__1c*sin(`&theta;__l`(t)-psi(t))*(diff(`&theta;__l`(t), t)-(diff(psi(t), t))); V__1lz := diff(z(t), t)-(1/2)*l__b*cos(psi(t))*(diff(psi(t), t))-l__1c*cos(`&theta;__l`(t)-psi(t))*(diff(`&theta;__l`(t), t)-(diff(psi(t), t)))

V__1l := simplify(V__1lx^2+V__1lz^2, size)

(diff(x(t), t)-(1/2)*l__b*sin(psi(t))*(diff(psi(t), t))+l__1c*sin(-theta__l(t)+psi(t))*(diff(theta__l(t), t)-(diff(psi(t), t))))^2+(diff(z(t), t)-(1/2)*l__b*cos(psi(t))*(diff(psi(t), t))-l__1c*cos(-theta__l(t)+psi(t))*(diff(theta__l(t), t)-(diff(psi(t), t))))^2

Physics:-diff(V__1l, psi(t))

2*(diff(x(t), t)-(1/2)*l__b*sin(psi(t))*(diff(psi(t), t))+l__1c*sin(-theta__l(t)+psi(t))*(diff(theta__l(t), t)-(diff(psi(t), t))))*(-(1/2)*l__b*cos(psi(t))*(diff(psi(t), t))+l__1c*cos(-theta__l(t)+psi(t))*(diff(theta__l(t), t)-(diff(psi(t), t))))+2*(diff(z(t), t)-(1/2)*l__b*cos(psi(t))*(diff(psi(t), t))-l__1c*cos(-theta__l(t)+psi(t))*(diff(theta__l(t), t)-(diff(psi(t), t))))*((1/2)*l__b*sin(psi(t))*(diff(psi(t), t))+l__1c*sin(-theta__l(t)+psi(t))*(diff(theta__l(t), t)-(diff(psi(t), t))))

``

Download DiffExpr_ac.mw

You could use the DocumentTools:-Tabulate command to embed a GUI Table of values. The values and column headings are constructed in a Matrix.

In the attached, I show two ways to handle the column headings (y3 and y4, with the formula for the latter shown explicitly). You can make both column headers the same, of course, using which form you prefer.

The attached also shows a variant of the above is to use a DataFrame structure instead of a Matrix, but I find that a little awkward.

The Tabulate command has several options, which allow you to customice the cell coloring, border display, column weighting, Table width, etc.

NULL

Example: Verifying Inverse Functions Numerically

 

"ex17f6(x):=(x-5)/(2);"

proc (x) options operator, arrow, function_assign; (1/2)*x-5/2 end proc

"ex17g6(x):=2 x+5;"

proc (x) options operator, arrow, function_assign; 2*x+5 end proc

y3:=ex17f6@ex17g6;

`@`(ex17f6, ex17g6)

y4:=ex17g6@ex17f6;

`@`(ex17g6, ex17f6)

NULL

V1 := Vector(7, proc (i) options operator, arrow; i-3 end proc); M := `<|>`(V1, map(y3, V1), map(y4, V1))

T := `<,>`(`<|>`("x", "y3", InertForm:-Display(%ex17g6(%ex17f6(x)), inert = false)), M)

``

DocumentTools:-Tabulate(T, fillcolor = (proc (T, i, jj) options operator, arrow; `if`(i = 1, cyan, white) end proc))

 

x

y3

Typesetting:-_Hold([%ex17g6(%ex17f6(x))])

-2

-2

-2

-1

-1

-1

0

0

0

1

1

1

2

2

2

3

3

3

4

4

4

 

 

 

Tabulate(DataFrame(`<|>`(map(y3, V1), map(y4, V1)), columns = [InertForm:-Display(%ex17f6(%ex17g6(x)), inert = false), "y4"], rows = [`$`(-2 .. 4)]))

 

 

Typesetting:-_Hold([%ex17f6(%ex17g6(x))])

y4

-2

-2

-2

-1

-1

-1

0

0

0

1

1

1

2

2

2

3

3

3

4

4

4

 

 

InverseNum_ac.mw

You can do this with either a procedure or an expression. In other words, you really don't have to use unapply. I'll show both, below.

I'm guessing that you want to use several values between 0 and 1, in which case you can supply a 3rd argument to to seq to specify the increment.

For example,

restart;

seq(x, x = 0 .. 1, 0.25);

0, .25, .50, .75, 1.00

f := unapply(3*x^2-2*x^3-1.080674649*x^2*(x-1)^2
             -.8118769171*x^2*(x-1)^3+.4147046974*x^2*(x-1)^4
             +.4585681954*x^2*(x-1)^5, x):

seq(f(x), x = 0 .. 1, 0.25);

0., .1410641163, .4607261850, .8135524863, 1.000000

F := 3*x^2-2*x^3-1.080674649*x^2*(x-1)^2
     -.8118769171*x^2*(x-1)^3+.4147046974*x^2*(x-1)^4
     +.4585681954*x^2*(x-1)^5:

seq(F, x = 0 .. 1, 0.25);

0., .1410641163, .4607261850, .8135524863, 1.000000

L := [seq([x,F], x = 0 .. 1, 0.1)];

[[0, 0.], [.1, 0.2517819625e-1], [.2, 0.9374594496e-1], [.3, .1954298021], [.4, .3207056009], [.5, .4607261850], [.6, .6065902371], [.7, .7481833253], [.8, .8728222816], [.9, .9639340323], [1.0, 1.000]]

#plots:-display(plot(L,style=point),plot(F,x=0..1));

 

Download seq_range.mw

 

One of the basic things to learn in Maple is the distinction between expressions and procedures. (An operator is a special kind of procedure that displays with the arrow notation.)

I realize that you may be quite used to instructors and textbooks using the term "function". But using that term in the context of Maple code can be confusing, since people might not always understand whether you mean expression or procedure.

Also, while your example can indeed work using operators, there's really no need for them here. The combine simplification needs expressions, and explicitly putting combine into the procedure body is inefficient.

There's little to no merit in using an operator f if you are just going to invoke it as f(x) every time you want to do a computation with expressions. It'd be simpler and cleaner to just use an expression directly.

In 2D Input mode the syntax,
   f(x,y) := ...something...
is an alternate syntax for assigning the operator,
   f := (x,y) -> ...something...
Unfortunately the first of those does something quite different in 1D plaintext Maple notation (or with different 2D Input preferences) and so it is ambiguous in the Maple language. I suggest that you think hard about whether you want to use ambiguous Maple syntax just to get a familiar looking math look & feel. I use the second form, below.

restart


The folowing assigns expressions to names F and G.

F := sin(x)*cos(y)

sin(x)*cos(y)

G := sin(y)*cos(x)

sin(y)*cos(x)


These expressions can be subtracted, directly. The result is also
an expression.

Notice that the "simplification" you want is not automatic.

F-G

sin(x)*cos(y)-sin(y)*cos(x)

V := combine(F-G)

sin(x-y)

eval(V, [x = Pi, y = (1/3)*Pi])

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

restart


The following assigns operators (a kind of procedure) to names f and g.

f := proc (x, y) options operator, arrow; sin(x)*cos(y) end proc

proc (x, y) options operator, arrow; sin(x)*cos(y) end proc

g := proc (x, y) options operator, arrow; sin(y)*cos(x) end proc

proc (x, y) options operator, arrow; sin(y)*cos(x) end proc


If we apply  these f and g operators to arguments (eg, x,y or some
other pair of names) then the result happens to be an expression.

f(x, y)

sin(x)*cos(y)

f(s, t)

sin(s)*cos(t)

f-g

f-g


The difference, f-g, can also be used like a operator. The result here is
also an expression.

(f-g)(x, y)

sin(x)*cos(y)-sin(y)*cos(x)


You have to apply the operators, to obtain expressions, in order
to use the combine command to obtain the simplification you want.

combine((f-g)(x, y))

sin(x-y)

``

f(x, y)-g(x, y)

sin(x)*cos(y)-sin(y)*cos(x)

combine(f(x, y)-g(x, y))

sin(x-y)


If you really want the combined expression to be the body of a new
operator then you can use the unapply  command.

v := unapply(combine((f-g)(x, y)), [x, y])

proc (x, y) options operator, arrow; sin(x-y) end proc

v(Pi, (1/3)*Pi)

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


Another solution is to construct a new operator that calls the
combine command each time it is invoked. This is somewhat
inferior because its use could be inefficient -- calling
combine on every result (f-g)(x,y) (which might not always
be just a number) each and every time v2 got called.

v2 := proc (x, y) options operator, arrow; combine((f-g)(x, y)) end proc

proc (x, y) options operator, arrow; combine((f-g)(x, y)) end proc

v2(x, y)

sin(x-y)

``

Download expr_oper_combine.mw

 

Your code has several mistakes.

Why do you have Ps[i][] in the odeplot call, when Ps is not a list of lists? The use of Ps and Pc is all muddled up. Explain, properly, what your intention is for those.

Why do you have theta(eta) in the odeplot call? Did you intend f(eta) or something else?

Where did you copy the code from? Was it from an earlier Question on Mapleprimes -- perhaps from someone taking the same course, before you?

I have a suggestion: instead of simply trying to reuse (someone else's?) object-oriented, (and undocumented?) code you should either learn how each part of it works, or try to program the task yourself in simple steps. That way you might actually learn how to use Maple for solving such bvp problems, and it'd help you in your future tasks as well.

This is a common issue, especially for coders new to Maple.

You made the central and germane statement, "It appears that fieldplot3d is attempting to evaluate the statements within the procedure, instead of simply calling the procedure with numerical values." It is excellent that you got to that idea. You are correct. Maple's usual model of evaluation during procedure calls is to evaluate the arguments up front, before the procedure body does the computation.

Sometimes (like in your problematic example) this situation is referred to as premature evaluation. The procedure PUV was not prepared to deal with some nonnumeric arguments. And, for symbolic arguments (x,y,z), the function call PUV(x,y,z) was evaluated prematurely.

The most common scenario for encountering this problem is with an if..then statement. In fact, if you click on the magenta error message in your Document then (provided your Maple GUI is set up to call your web browser) it will take you to this Help page which addresses this issue. In your original worksheet, if you call PUV(x,y,z) by itself then you'll see the same error message.

For your example the cleanest way to resolve this problem is to alter the body of your procedure so that it can handle nonnumeric arguments. Member Kitonum's Answer shows that you can simply utilize 2-argument arctan and remove the conditional queries. And member Preben Alsholm's Answer explains that you can utilize a piecewise structure and so defer the conditional branching until a numeric value is supplied.

But those kind of approaches are not always easy to accomplish gracefully. So, for fun in these lockdown times, we can take a brief look at some blunter methods.

The Help page to which I linked shows two ways to deal with the issue. There is an extra wrinkle, however, in the fact that fieldplot3d needs three items (expressions in a list, or expressions in a Vector, or procedures in a list). But otherwise the approaches illustrated in that Help page are still possible:
1) Delay the up-front evaluation of the function call using right (forward) single-quotes, aka uneval-quotes. Here is that approach, for your example. fieldplot3d_and_if_statements_ac1.mw
2) Use the operator form calling-sequence of fieldplot3d, instead of the expression form. That is shown in member vv's Answer.

I'll also give a variant on 1), since uneval-quotes are ephemeral:
3) You could adjust the procedure PUV so that it returns unevaluated if some of the arguments are not numeric. fieldplot3d_and_if_statements_ac2.mw

Approaches 1) and 3) both index into the unevaluated function call since in those cases three expressions need to be passed for fieldplot3d and, when numeric x-y values get substituted, each result from PUV will be a Vector. Approach 2) also involves indexed calls to PUV, for the same reason. So all of these approaches actually call PUV three times for every numeric x-y pair. In order not to make triple the computational effort the procedure PUV can be given option remember, so that the second and third call (with the same, repeated numeric x-y pair) can be done with a quick lookup of a stored result.

You can increase Digits and call the LPSolve command from the Optimization package.

See the Help pages with those terms as Topic.

You might be making the mistake of using lowercase pi instead of Pi.

If I accidentally use the "Evaluate at a Point" context-menu item and supply lowercase 2*pi as the value for t then I'll get the same result as you. But lowercase pi is just a name, with no special meaning to Maple.

But if I use the capitalized Pi in the "Evaluate at a Point" context-menu item, and supply 2*Pi as the value for t then the output is the expected result.

g := t*(cos(t)+I*sin(t))

t*(cos(t)+I*sin(t))

expr := diff(g, t)

cos(t)+I*sin(t)+t*(-sin(t)+I*cos(t))

"(->)"

1+(2*I)*Pi

eval(expr, t = 2*Pi)

1+(2*I)*Pi

eval(expr, t = 2*pi)

cos(2*pi)+I*sin(2*pi)+2*pi*(-sin(2*pi)+I*cos(2*pi))

evalf(Pi)

3.141592654

evalf(pi)

pi

``

Download Pi_versus_pi.mw

S := -A/Pi*Sum((-1)^k*sin(2*Pi*k*f*(t-Pi/8))/k,k=1..N):

bg := plots:-display(
  plot(fmod(t,Pi/4)*4/Pi-1/2,t=0..Pi,color=blue,thickness=1),
  plots:-pointplot([seq([[i*Pi/4,0.5],[(i-1)*Pi/4,-0.5]][],i=1..4)],
                   symbol=solidcircle,symbolsize=8,color=white),
  plots:-pointplot([seq([[i*Pi/4,0.5],[(i-1)*Pi/4,-0.5]][],i=1..4)],
                   symbol=circle,symbolsize=12,color=blue)):

F := n -> plots:-display(bg,
    plot(eval(S,[A=1,f=4/Pi,:-N=round(n)]),t=0..Pi,
         thickness=1,color=red,numpoints=max(2,10*round(n))),
    plots:-textplot([0.35,-1.0,sprintf("N = %-2ld",round(n))],
                    font=["Monospaced","bold"])):

L := [0$8, 1$8, 2$8, 3$8, $4..49, 50$12]: # delay by repeating
plots:-animate(F,[N],N=L,frames=nops(L),paraminfo=false,
               xtickmarks=[],ytickmarks=[],axis[2]=[color=white],
               axis[1]=[color="#9090FF",thickness=0],size=[600,300],
               labels=[``,``],view=[Pi/16..Pi-Pi/16,-1.25..1.25]);

First 124 125 126 127 128 129 130 Last Page 126 of 336