acer

30745 Reputation

29 Badges

19 years, 4 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You should be able to run this in Maple 2024.1 (or Maple 2023.2, etc). But not Maple 2024.0 which had a bug, now fixed.

I created a procedure which generates a static plot for any values of those parameters (and tfinal the end-point for t). Then I show how it can be used with Explore, or plots:-animate letting the tfinal value change. [This is a natural way to proceed; I see now that Carl has done much the same thing.] I also allow extra arguments to the procedure be passed along into the odeplot call (for which I too collapsed your seq into a single call).

You could also add the plotting command view option to the calls to G, if you'd prefer. Eg,
   view=[0..7, -10..2]
etc.

explore_odeplot_2.mw

Adjust other options as wanted.

[edit] It is interesting; when I first posted this Answer it was the only one, but now Carl's appears above it -- even with no votes yet for either. Perhaps the system got confused by very close posting times. (But I've also seem some other curious new behavior by this site.)

Consider the situation where the name e has been assigned a value, at the level at which you are making those calls.

For example, after e:=37 has been executed.

Now m:-e will still access that export of your given module. But m[e] will not, since that evaluates to a reference to m[37]. You could use m['e'] however.

And it could get even more complicated inside some procedure which had e as a parameter. Then m['e'] might not access that export of m, while m[':-e'] could work ok.

So, if two decent choices are m:-e and m[':-e'], which is easier to type and use? For me, it's the first of those two.

The different results you see are because in the case of x (instead of 2) there is ambiguity, as C_R explains.

You've asked whether the difference arose from using the two input forms, ie. 2D Input with the explicit command, versus 2D Input with units-shortcut entry. In that case the only difference (ie. if the commands were the same) would be that with the shortcut the unit in the input is typeset like in the output.

Below I've used Alt-Shift-u to get the Unit(m) typeset in the input for the line involving expr2.  In modern Maple that input renders with an upright Roman "m", without double-braces. (Mapleprimes uses an older backend that still shows the double-braces.)

As the lprint (line-print) command reveals, the expressions themselves are the same.

expr1 := 4*Unit(m)

4*Units:-Unit(m)

expr2 := 4*Unit('m')

4*Units:-Unit(m)

lprint(expr1)

4*Units:-Unit(m)

lprint(expr2);

4*Units:-Unit(m)

Download 2dmath_unit_entry.mw

See also this Help page which describes this hotkey mode of unit entry.

There are two main ways to get a subscripted name.

One involves a double-underscore (so-called Literal Subscript), and another involves an indexed name (so-called Indexed Subscript). The actual constructs for those would be g__n and g[n], respectively.

The ScientificConstants package uses the latter, ie. indexed names, to refer to its constants.

In 2D Input mode you can get the typeset subscripted form for input with the keystrokes,
    g Ctl-Shift-underscore n      (Windows, Linux)
    g Cmd-Shift-underscore n    (Mac OSX)

For example, using those keystrokes,

with(ScientificConstants)

GetConstant(g[n])

neutron_g_factor, symbol = g[n], derive = 2*mu[n]/mu[N]

Download 2dmath_indexed_entry.mw

You can also enter g[n], literally, in either 1D or 2D input modes.

See this Help-page for 2D Input ketyboard shortcuts.

You wrote,

Consider the expression 5m+x. This expression works in
Units:-Simple but not in Units:-Standard.

Units:-Simple adds a quantity 5m to a quantity without units.
But why can one add a quantity with units to a quantity
without units?

Units:-Standard tries to add a quantity 5m to a quantity
that is assumed to have units. What units are assumed?

The point is that the name x might be evaluated later on at some value involving some unit of dimension length.

One can evaluate x (in expressions containing x) with pretty much whatever value you want, in general. And for the expression 5*Unit(m)+x some later value like 3*Unit(mm) or 8*Unit(km) is quite fine. So the expression 5*Unit(m)+x can be allowed. So that's one thing that the newer Units:-Simple does, which the older Units:-Standard does not: it allows such an addition.

You asked, "What units are assumed?" But it's not some specific unit that's taken. It's the dimension of length that is taken.

And with the notion that the x in expression 5*Unit(m)+x can be considered as having dimension length, further dimensionall anaylsis is possible. That dimensional analysis may help with further symbolic manipulation.  That dimensional analysis can also help in the front- and back-ends of commands that are taught to understand units more, eg. plot, fsolve, etc.

Since you have Units:-Simple loaded, you don't need to do combine(...,units) or simplify to get the simpler units you originally showed.

You can instead accomplish your simplification/combining of units, directly upon substitution, by merely using eval instead of subs.

I also show how the J/mol form can be attained, in two ways.

restart

with(Units)

Automatically loading the Units[Simple] subpackage
 

eval(-R*T*ln((V__2-b)/(V__1-b))+a*(1/V__1-1/V__2), {R = 8.314*Unit('J'/('K'*'mol')), T = 298*Unit('K'), V__1 = Unit('L'/'mol'), V__2 = 50*Unit('L'/'mol'), a = 2.283*Unit('L'^2*'bar'/'mol'^2), b = 0.4278e-1*Unit('L'/'mol')})

-9574.788418*Units:-Unit(m^2*kg/(s^2*mol))

convert(%, units, J/mol)

-9574.788418*Units:-Unit(J/mol)

restart

with(Units)

Automatically loading the Units[Simple] subpackage
 

UseUnit(J/mol)

eval(-R*T*ln((V__2-b)/(V__1-b))+a*(1/V__1-1/V__2), {R = 8.314*Unit('J'/('K'*'mol')), T = 298*Unit('K'), V__1 = Unit('L'/'mol'), V__2 = 50*Unit('L'/'mol'), a = 2.283*Unit('L'^2*'bar'/'mol'^2), b = 0.4278e-1*Unit('L'/'mol')})

-9574.788418*Units:-Unit(J/mol)

``

Download Units_-_Subs_zent2.mw

I just use with(Units) to get Units:-Simple as default. (That's not showing in the sheet as inlined in this forum.)

ps. If you inadvertantly create an expression with over-complicated units then you can use combine(...,units) on it.

If you specifically want to avoid additional non-units-related simplifications/changes then IMO combine(..,units) is better than calling simplify. nb. also, simplify doesn't handle your original subs result in 2022.

Is this the kind of thing that you're after?

restart;

expr := alpha*((epsilon-1)*x+y-3*x*z-epsilon/3*x^3+b*sin(w)+3+exp(c+w));

alpha*((epsilon-1)*x+y-3*x*z-(1/3)*epsilon*x^3+b*sin(w)+3+exp(c+w))

V := indets(expr,function(satisfies(u->depends(u,{x,y,z,w})))) union {x,y,z,w};
Vf := freeze~(V):

{w, x, y, z, exp(c+w), sin(w)}

R := [coeffs(frontend(expand,[subs(V=~Vf,expr)]), Vf, 'S')]:

L := sort([seq(thaw([S[i],R[i]]),i=1..nops([S]))]);

[[1, 3*alpha], [x, alpha*epsilon-alpha], [y, alpha], [x^3, -(1/3)*alpha*epsilon], [x*z, -3*alpha], [exp(c+w), alpha], [sin(w), alpha*b]]

`+`(map(`*`@op,L)[]);

3*alpha+x*(alpha*epsilon-alpha)+alpha*y-(1/3)*alpha*epsilon*x^3-3*alpha*x*z+exp(c+w)*alpha+sin(w)*alpha*b

simplify(expr - %);

0

Download acf_ex2.mw

It looks as if you might be encountering premature evaluation of the first argument you're passing to NonlinearFit.

You are passing,
   p__eng1(C__10, C__01, kappa, lambda)
which will evaluate with all its arguments as mere names without numeric values. That may cause the call to solve inside procedure r to return a list, which could be where those square-brackets are coming into it.

What might work instead is to prevent that evaluation until the parameters get actual numeric values. So you could instead try passing,
  'p__eng1'(C_10, C__01, kappa, lambda)
to delay the its evaluation.

It would be easier to test outselves if you supplied the actual data (file) which you are importing. (Possibly attached here as a .zip file, depending on its filename extension). It's also difficult to tell whether fsolve might get better speed than solve here, without the actual data.

First, if you want to use capital D as a variable at the top level like this you could issue,
   local D:
at the start of your worksheet. (Or use a different letter. The protected name D is the name of the differential operator and doing otherwise will run into issues.)

Also, fix your syntax and remove errant [...] as C_R suggests.

Thenm try using solve here instead of isolate, supplying assumptions if you have them.

Eg,

   solve(T4, rho) assuming 0 < 4*Co*D^2*theta

etc, instead of,

    isolate(T4,rho)

as one example.

Another example might be, say,

   solve(D2, rho) assuming 0 < delta*D


ps. Your problem is mainly your choice to try isolate which is not the right command here. It's not related to whether you use eval.

restart;

kernelopts(version);

`Maple 2022.2, X86 64 LINUX, Oct 23 2022, Build ID 1657361`

 

G := (-0.14*y^3 + 1.20000000000000*y^2 - 1.26000000000000*y + 0.200000000000000)*x^3 + (1.20*y^3 - 10.0800000000000*y^2 + 10.0800000000000*y - 1.20000000000000)*x^2 + (-8.82*y + 10.08*y^2 - 1.26*y^3)*x + 1. - 1.2*y^2 + 0.2*y^3;

(-.14*y^3+1.20000000000000*y^2-1.26000000000000*y+.200000000000000)*x^3+(1.20*y^3-10.0800000000000*y^2+10.0800000000000*y-1.20000000000000)*x^2+(-8.82*y+10.08*y^2-1.26*y^3)*x+1.-1.2*y^2+.2*y^3

 

minimize(G,x=0..1,y=0..1);

Error, (in RootOf/RootOf:-algnum_in_range) invalid input: RootOf/RootOf:-rootof_in_range expects its 1st argument, rt, to be of type ('RootOf')(polynom(rational,_Z),identical(index) = posint), but received RootOf(7*_Z^3-93*_Z^2+327*_Z-187)

 

_EnvExplicit:=true:

 

minimize(G,x=0..1,y=0..1);

-0.8418060591e-1

minimize(G,x=0..1,y=0..1,location);

-0.8418060591e-1, {[{x = .7061420262, y = .7061420262}, -0.8418060571e-1]}


Download minimize_ex_2022.2.mw

ps. You may wish to subsequently unassign that environment variable, if you don't want it to affect later solve calls,
    _EnvExplicit := '_EnvExplicit':

pps. I will submit a bug report.

You can add,

   axis[2]=[location=high]

to you plot options, to get the effect of the tickmarks and label on the other/right/upper side of the vertical axis position on the right.


Or you could add,

   axis[2] = [location=low]

if you'd prefer the label/tickmarks to the left/lower of the vertical axis positioned on the left. (This combination happens to render similar to axes=frame.)

For the images above I also altered your size, just to make it all a bit smaller. In the following attachment the same effect is attained using your original size setting (so you can examine that, to see the automatic tickmark values actually generated).

axis_label_on_wrong_side_of_axis_ac.mw

Here is your original axis effect, that you did not want,

@Ronan In light of a few followup comments it seems that you already had a decent mechanism for adding spacing above or below the symbol, including multiple depths.

And it seems you also want to deal with another problem: that the name you wanted to show/render was already assigned a value.

Note. lowercase `typeset` does nothing to avoid an assigned name evaluating to its assigned value. Rather, that lowercase `typeset` serves mainly to allow you to mix math & text nicely, in plotting contexts.

But Typesetting:-Typeset can indeed turn a name (even if assigned) into a form that will not subsequently evaluate to a value assigned to that name.

So it seems to me that all you need is that Typeset along with "\n" newline characters. eg,

     typeset(Typeset(thename),"\n")

though naturally you can also have the newlines before/above, or multples.

Obscure stuff like that `mover` seem like quite unnecessary over-complication. And it needs more effort to shoehorn in a general expression. And it gets quite awkward (nested) for adding multiple vertical spacing above and below.

ps. single right click uneval quotes alone (to prevent evaluation of an assigned name, eg. 'gamma2') is not generally adequate here, since accidental full evaluation of the plot structure ruins it.

There are many errors in your "chelishkov_comparison" worksheet. Here are some adjutments,

chelishkov_comparison_ac.mw

I don't understand what you intend with your Matrix arithmetic in the other worksheet. It doesn't make sense to me.

@Earl I missed this before:

You have the assignment,

   libname := "C:\\Users\\earls\\OneDrive\\Documents\\Earl's documents":

which is not OK (unless you've made a full copy of the stock .mla Library archive in that location, eg maple.mla).

What you likely intended was something like,

  libname := "C:\\Users\\earls\\OneDrive\\Documents\\Earl's documents",libname:

which prepends your location to the stock location. That's what I mean by "augment libname" earlier.

As you had it originally, Maple is not able to find its own stock .mla Library files (unless you made the very usual move of actually copying them to that personal folder).

Try `ODEtools/odeadv`, for showstat or stopat.

2 3 4 5 6 7 8 Last Page 4 of 320