acer

32400 Reputation

29 Badges

19 years, 345 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Let's try an example with more corrner cases in it.

Below I use uneval quotes (single right-quotes) because neither typefunc nor last_name_eval is a protected name.

restart;

eq := diff(x(t), t) = t + x(t) - 1 + sin(x(t))
      + cos(t) + G(t, x(t), v(t)):

indets(eq,{name,'typefunc(name,Non(last_name_eval))'});

                               {t, v(t), x(t)}

indets(eq,'typefunc(name,Non(last_name_eval))');

                                {v(t), x(t)}

indets(eq, {name, function(name)});

                           {t, cos(t), v(t), x(t)}

indets(eq,function(name));

                            {cos(t), v(t), x(t)}

How about handling F(t), where F is a user-defined procedure which returns unevaluated if its argument is not numeric? (Think of using the known option of dsolve/numeric, and other similar situations.) For unassigned argument t, calling F(t) returns the unevaluated function call F(t) itself.

Since F is a known procedure, which is already defined to compute an output number from an input number, then neither F nor F(t) is a "dependent variable" of the DE.

# In general F may be a black-box procedure, whose workings
# are not explicitly known.
F:=proc(u)
  if not type(u,numeric) then
    return 'procname'(u);
  else
    tan(u)+u^2;
  end if;
end proc:

F(t); # returns unevaluated for unassigned t

                                    F(t)

F(0.1); # returns a number. we won't "solve for F".

                                0.1103346721

eq2 := diff(x(t), t) = t + x(t) - 1 +  sin(x(t))
       + cos(t) + G(t, x(t), v(t)) + F(t):

indets(eq2,{name,'typefunc(name,Non(last_name_eval))'});

                               {t, v(t), x(t)}

indets(eq2,'typefunc(name,Non(last_name_eval))');

                                {v(t), x(t)}

indets(eq2, {name, function(name)});

                        {t, F(t), cos(t), v(t), x(t)}

indets(eq2,function(name));

                         {F(t), cos(t), v(t), x(t)}

procedures (of which operators are a subset) are of type last_name_eval.

Try it with eval(f) instead of just f, in the line where you augment nonIdMaps.

Otherwise, as seen, you're just building up a list of repeats of the name `f`  (and by the time you get around to mapping f->f(y) over the list you've finished the loop, and all the f's evaluate to its last iterated value).

ps. `select` is a better choice for this task than is looping and augmenting a list, IMO. Say,

select(f->f(__y)<>__y,
       [x->x, x->2*x, x->3*x]);

I notice that all the code posted so far does not protect against y being assigned. Perhaps your situation is in a context where y is local and you know it is unassigned. I use __y just in case. You could also make y local to the predicate operator/procedure.

You could try DocumentTools:-Tabulate. The caveat is that command only allows for one such plot (or collection/Table of plots) printed immediately after each paragraph or execution group.

P1:=plot(sin(x),x=-Pi..Pi,size=[300,300]):
DocumentTools:-Tabulate([P1],alignment=left,exterior=none,
                        width=300,widthmode=pixels):
P2:=plot(sin(x),x=-Pi..Pi,size=[500,500]):
DocumentTools:-Tabulate([P2],alignment=left,exterior=none,
                        width=500,widthmode=pixels):

You can also do the above all manually, by inserting GUI Tables, toggling off their borders, making them left aligned, and using DocumentTools:-SetProperty to put plots into them programatically.

You can also force the output of a regular printing of a plot to be left-aligned using the main menubar. But as far as I know that quality is not persistent and is undone by re-execution. The same goes for plots:-display(Array([....]) where you weight the right portion with an empty plot and then toggle all the qualities of the inserted Table (which also don't persist upon re-execution).

By default the caret is too narrow, and is rendered to the left (perhaps not only because of the italic slant).

Two other ways to accomodate this are:

1) Augment the base symbol with an invisible space, so that the caret gets stretched and shifted right. This pushes the subscript slightly to the right, but the overall effect is still better than the original caret misplacement, IMO.

2) Use double-underscore rather than square-bracket indexing for the subscripting. This also shifts and strectches the caret. But (see below) the effect may be too much when the subscript is itself wide.

nb. In My Maple 2017.1 for Linux the carets looks a little narrower and sharper than they do as rendered inline below (by this site). But the placement and width effects are essential similiar.

# Doesn't look great, caret is too narrow and too left.
#
plot([], size=[400,200], tickmarks=[[],[]],
     labels = [x, `#mover(mi("sigma"),mo("&circ;"))`[y]]);

# More effort, but seems more robust (see below).
#
plot([], size=[400,200], tickmarks=[[],[]],
     labels = [x, `#mover(mrow(mi("sigma"),mi("&InvisibleTimes;")),mo("&circ;"))`[y]]);

# Looks ok here, but not in wider case (see below).
#
plot([], size=[400,200], tickmarks=[[],[]],
     labels = [x, `#mover(mi("sigma__y"),mo("&circ;"))`]);

#
# Now let's try those with a wider base as well as a wider
# subscript.
#

plot([], size=[400,200], tickmarks=[[],[]],
     labels = [x, `#mover(mi("&sigma;T"),mo("&circ;"))`[yyy]]);

plot([], size=[400,200], tickmarks=[[],[]],
     labels = [x, `#mover(mrow(mi("&sigma;T"),mi("&InvisibleTimes;")),mo("&circ;"))`[yyy]]);

plot([], size=[400,200], tickmarks=[[],[]],
     labels = [x, `#mover(mi("&sigma;T__yyy"),mo("&circ;"))`]);

 

Download overcaret.mw

Add the option phi = 0 .. infinity to your fsolve call, to avoid negative values for this example.

You can also use Student:-Calculus1:-Roots to get multiple roots within a finite range. Results may vary according to your Maple version, though. The first attachment below was run in Maple 2017.0, and you are using what, Maple 13.00 still?

ANALYTIC_1.mw

Here's an attachment that was run in Maple 13.00.

ANALYTIC_1_M13.00.mw

nb. Your original worksheet returned calls to Analytic, unevaluated, because you didn't first load the RootFinding package. You also failed to supply it with a (thin, complex) range for phi. [edited] See below for more, including another attachment by me.

Q2: For this example, you can obtain the desired simplification with just,

  simplify(ap2, size)

or,

  numer(ap2)/denom(ap2);

or,

  frontend(simplify, [ap2]);

Q3: note the t1(T) in the lhs of ap3 (as opposed to just your original t1 ).

ap3 := Diff(t1(T), T) = (m-T)/(m-t1(T));

ap4 := Diff(lhs(ap3), T) = subs(value(ap3), diff(rhs(ap3), T));

Q5: I don't understand why you thing that the originally supplied ap6 and ap7 are always equal.

Try the command `timelimit` which can wrap around another procedure call.

The `timelimit` command is intended for exactly the kind of situation you describe.

You can use the try...catch mechanism to control this flow.

When `timelimit` times out it emits an error, and your code can catch that, and proceed.

The command LinearAlgebra:-GenerateMatrix should be able to do that.

It's awkward to do, and not general, but... you can alter the Typesetting so that the exponent is smaller.

Making this more precise, say to affect only powers within sqrts, would be more involved.

Using labelfont=[...,bold,N] might make the two sizes appear more similar in weight.

restart;

N := 24:

plot(cos(1/theta)/sqrt(1-theta^2), theta=0.2 .. 0.99,
     size=[700,400],
     labels = ['theta', typeset(cos," (","1/",theta,") / ",
               sqrt(sort(1-theta^2,theta,ascending)))],
     labelfont=[Times,N],labeldirections=[horizontal,vertical]);

K:=eval('Typesetting:-Typeset'(sqrt(sort(1-theta^2,theta,ascending)))):
K:=subsindets(
  subsindets(K,specfunc({Typesetting:-mn,
                         Typesetting:-mo,Typesetting:-mi}),
  uu->op(0,uu)(op(uu),size=sprintf("%d",N))),
  specfunc(Typesetting:-msup),
             u->op(0,u)(op([1,0],u)(op([1,..],u),size=sprintf("%d",N)),
                        op([2,0],u)(op([2,..],u),size=sprintf("%d",ceil(0.5*N))))
  ):

plot(cos(1/theta)/sqrt(1-theta^2), theta=0.2 .. 0.99,
     size=[700,400],
     labels = ['theta', typeset(cos," (","1/",theta,") / ",K)],
     labelfont=[Times,N],
     labeldirections=[horizontal,vertical]);

 


cust_label.mw

Did you intend something more like,

F53 := eval(u(y), sol)

?

Also, assigning to `u` just makes it more difficult to re-use `sol`.

BVP_1.mw

I find the whole approach to be unnecessarily cryptic.

Why not use the -c option of cmaple, to assign the filename string (and read MyCode too if you want).

Then you just need Eclipse to form the full call to cmaple.

To get the dot notation for the derivatives you can issue this command at the top of the Document.

Typesetting:-Settings(typesetdot=true, usedot=true, dot=t):

If you didn't need the derivatives to be pretty-printed in dot notation then you could simply set the typesetting level to standard. Getting the formatting effect you describe, without setting typesetting to standard, requires fooling the system into not recognizing that common 1/2 factor as being a rational number. There are a few ways to do that, some fancier than others. See this attachment formatting.mw .

As far as grouping with respect to particular variable names goes, see the collect command.

These should also produce a plot as shown in Adri's answer:

restart;
S:=proc(u,v) 10*u^2+20*u*v+15; end proc:
p:=proc(u,v) if u<v then S(u,v); else S(u,v)+10; end if; end proc:
h:=proc(u) 2*u; end proc:
plot3d([(u,v)->40*u,(u,v)->80*v,p], 0..1, 0..h);


restart;
ee:=10*u^2+20*u*v+15:
plot3d([40*u,80*v,piecewise(u<v,ee,ee+10)], u=0..1, v=0..2*u);


restart;
S:=proc(u,v) 10*u^2+20*u*v+15; end proc:
p:=proc(u,v)
    if not ( u::numeric and v::numeric ) then
      return 'procname'(args);
    end if;
    if u<v then
      S(u,v);
    else
      S(u,v)+10;
    end if;
end proc:
plot3d([40*u,80*v,p(u,v)], u=0..1, v=0..2*u);

Apply the procedure to some name(s).

Maple is telling you, correctly, that it cannot cast an unassigned name to a hardware double-precision floating-point number.

And your command instructs Maple to convert every element of K to a double-precision float.

Do you think that the name actually has a value which should evaluate to a float?

Is there some possibility that there are two similar names in play (perhaps a copy and paste mismatch of atomic identifiers)? It's hard to be more specific if you don't bother to upload a worksheet that exhibits the problem.

First 195 196 197 198 199 200 201 Last Page 197 of 336