acer

31443 Reputation

29 Badges

19 years, 135 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

First you need to fix your faulty syntax and provide missing details.

The assignment to C1 fails in your attachment, yet you ask for a plot of it's expression. You should fix that, or at least explain properly what your intention is for assigning to C1.

Next, your expression assigned to C2 contains a function calls that seem like a mistake. Why does it have the function call R0er(y) appear in the expression assigned to C2? Did you forget a multiplication sign or a space to denote multiplication implicitly in 2D Input?

For which parameters do you want to have Sliders? Is it just g2, or also any of the others in DATA?

If I guess the fixes to the above problems, then here is the kind of thing you can do with a simple call to the Explore command:
question_plot_slider_ac.mw

You should be able to adjust your expressions (A11, etc), if needed.

Here is one way, using rsolve,

rsolve({A[n + 1]*(5*A[n] + 2) = A[n], A[1] = 1}, A[n])

1/(3*2^n-5)

Download rs_ex.mw

Your attempt was getting tripped up by the ratpoly, not the indexed syntax.

Fwiw, given your original form,

eq := A[n + 1] = A[n]/(5*A[n] + 2):
neweq := numer((lhs-rhs)(eq)):
rsolve({neweq,A[1]=1},A[n]);

       1/(3*2^n-5)

You can use the eval command to substitute for u throughout, or for any/all of the derivatives separately.

For example,

restart;

PDEtools:-undeclare(prime, quiet):

de := diff(u(x,t),t) = -a*diff(u(x,t),x,x) + b*diff(u(x,t),x);

diff(u(x, t), t) = -a*(diff(diff(u(x, t), x), x))+b*(diff(u(x, t), x))

eval( de, u = F );

diff(F(x, t), t) = -a*(diff(diff(F(x, t), x), x))+b*(diff(F(x, t), x))

eval( de, u = ( (x,t)->G(x)*H(t) ) );

G(x)*(diff(H(t), t)) = -a*(diff(diff(G(x), x), x))*H(t)+b*(diff(G(x), x))*H(t)

eval( de, u = ( (x,t)->sin(x)*H(t) ) );

sin(x)*(diff(H(t), t)) = a*sin(x)*H(t)+b*cos(x)*H(t)

eval( de, u = ( (x,t)->G(x)*cos(t) ) );

-G(x)*sin(t) = -a*(diff(diff(G(x), x), x))*cos(t)+b*(diff(G(x), x))*cos(t)

eval( de, u = ( (x,t)->sin(x)*cos(t) ) );

-sin(x)*sin(t) = a*sin(x)*cos(t)+b*cos(x)*cos(t)

eval( de, [ diff(u(x,t),t)=P(x,t),
            diff(u(x,t),x)=Q(x,t) ] );

P(x, t) = -a*(diff(Q(x, t), x))+b*Q(x, t)

Download eval_substitutions_ex.mw

Note that the Optimization package will compute local optima for multivariate problems, so you might want global optimization instead. See DirectSearch v2. In my attachment I've used both.

I've rewritten the objective so that it doesn't error out if the de solving throws an error (eg. ostensibly runs into a singularity, etc). Also, it stores the best value found so far, which means that you can interrupt it and still see how well it did. (This can be convenient if your options choices make it take a long time.)

The original objective SSE had some others flaws, on top of being fragile. The most important perhaps is that for an IVP and using the parameters option of dsolve one does not have to re-invoke dsolve every time one wants to use different parameter values. In fact the efficiency gain of not having to invoke dsolve each time is one of the major aspects of the parameters option. Also, picking off the values using rhs of the 3rd entry is poor, being fragile wrt the lexicographic ordering of the dependent function names.

You can play with the optimizer's options. Again, if it looks like it's not improving much, and taking long, you can interrupt and still see the current best and make the plot for that. You can also make the optimizers work harder/longer with additional options (iterationlimit, evaluationlimit, timelimit, etc -- though it varies by solver/method which if those you can use).

I found a data file by the same name on that github link you gave. The top portion at least seems to match what your sheet displayed.

Parameter_estimation_acc.mw

Here's one kind of result:

beta = 8.803946195*10^(-7), Gamma = 0.0129, S0 = 98274.5155341030, i0 = 93.2346673823882

 

If you assign a value to mu (by itself) then you will affect any instances of indexed names like mu[3], mu[4], etc.

So if you also want to have the subscripted names then you can instead use m__3 and mu__4 (double underscore). Those are completely separate and unrelated names.

But the double-underscore names will pretty-print as subscripted names in 2D Output.

The clause, "no computation was needed if basic math knowledge was utilized" connotes (to me) what is called abstract linear algebra.

If there were placeholders (objects, etc) that represented a Matrix, and enough accompanying functional syntax, then a strong abstract linear algebra package might be able to recognize the equivalence of those two forms without doing a computation with explicit Matrix entries.

At the other end of the spectrum is the fact that your pairs of concrete constructions are not producing the same final form. For example, there may be some difference in presence or absence of factorization of numerators or denominators of the resulting multivariate rational polynomials. On that note, getting the final Matrix of zeros for the difference can be attained just by normal (ie. simplify is not needed, and its symbolic option is not relevant here). Also, a true result for the comparison can be had by just,
   Equal(normal(expand(1/`⨂`(A, A))), normal(expand(`⨂`(1/A, 1/A))))
Using_basic_linear_algebra_ac.mw

In the middle ground there might be scope for hybrid abstract/concrete computation, where either of the two calls were somehow analyzed up front. That would require by-passing the usual evaluation of MatrixInverse (or rtable powering) or KroneckerProduct, so that their arguments could be analyzed abstractly. (Maple's usual evaluation of function calls has the inner calls evaluated before the outer calls get to "see" them.) In this example it might even be the case that the faster of those formulations could be used, once the form is recognized. Implementing this is possible, though possibly involved.

Closer to the concrete end is the idea that both results might be simplified/normalized by the commands themselves (though not at present) to a common form. This is not the way that several parts of Maple work; it can be too expensive and heavy-handed to do that in general, and it's often left to the user to do such as a subsequent step.

This could be improved (say, removing entries when no longer active).

restart;

util := 'map(nm->assign(`tools/gensym`(lhs(nm)),rhs(nm)),
    getassumptions([indices(`property/OrigName`)]))':


Execute this line by line.

assume(x>0);


Watch the Variables palette

util:

assume(y<4 and y>-1);

assume(z::posint);


Watch the Variables palette

util:


The last step did not assign to (or clobber) the actual
assumed names. You can do it repeatedly.

x,y,z;

x, y, z

Download assum_var_palette.mw

There are several ways to do that.

For example,

restart;
fn := "/home/PNL/test_file.txt":
fprintf(fn,"%a\n", "Hello, it is me"):
fprintf(fn,"%a\n", 3.1415):
fclose(fn);

restart;
fn := "/home/PNL/test_file.txt":
FileTools:-Text:-WriteLine(fn, "Hello, it is me"):
FileTools:-Text:-WriteLine(fn, "3.1415"):
FileTools:-Text:-Close(fn);

restart;
fn := "/home/PNL/test_file.txt":
FileTools:-Text:-WriteFile(fn, "Hello, it is me\n3.1415\n"):

Note that the directory must exist. Note also that the the first two of those require that the file handle be closed (by explicit command, or by a restart). The "\n" is for a new line.

I couldn't tell whether you wanted the Hello string to be written out including its quotes. If so then you could escape the quotes within a string, eg.
   "\"Hello, it is me\""

There are even more ways to do this kind of thing. But let us know if you get it working. It looks as if your OS is not MS-Windows, btw.

You have two main choices for formatting floats in printed output.

1) Set interface(displayprecision), a programmatic solution which will affect anything executed after it's set.

2) Use right-click Numeric Formatting. This has a choice of affecting only the given Execution-Group/Document-Block in which it's done, or as default for the worksheet.

nb. Don't attempt to get this kind of effect by setting Digits so low as 5. That is a very bad thing to do and can actually make some subsequent computations not work properly.

Even wrapping with evalf[5] is tricky to get right and not what I'd suggest to anyone without a strong working knowledge of Maple.

Attached is an example of accepting an indexed procname call.

2024-11-21_Q_Projective_Vector_Format_ac.mw


Now, for your type question. You seem to be under an impression that whattype gives you THE type of a thing, because you mention "...the type check", and what you have are some whattype calls.

But things can be of several types. And the type system is not even completely hierarchical. In general using whattype is (IMNSHO) a logically inferior mechanism for control flow, dynamic dispatch, etc, and I suggest that you instead check against specific types.

For example, I suggest you later do something like,

    if type(K,foo) then
    ...
    elif type(K,bar) then
     ...
     end if

instead of, say,

    W := whattype(K);
    if W=foo then
    ...
    elif W=bar then
     ...
     end if

and similar for other analogous situations.

You are of course free to do it your way. But in my experience that may eventually get into a muddle, and the fact that your examples so far don't have issues is because they are rather simple.

You asked why. It fails because an indexed reference into an rtable (Matrix,Vector,Array) cannot be evaluated unless the indexing value is an actual integer. The indexing value cannot be a name/symbol/placeholder.

So, the evaluation of Xvector[i] produces that error, for `i` just a name.

But you can make such unspecified referencing for a list (or a set), ie. you can evaluate Xlist[i]. If `i` is just a symbol then that will merely evaluate to itself.

Maple evaluates arguments to procedure calls up front (ie. before the sum routine gets its hands on them). That is Maple's normal evaluation rules for procedure calls.

So, that error occurs before sum even receives its arguments.

See also special evaluation rules.

restart;

Xlist := [1,2,3];

[1, 2, 3]


One can make an indexed reference into a list,
even for an unspecified index value.

Xlist[i];

[1, 2, 3][i]

Xvector := Vector(Xlist);

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


One cannot make such an indexed reference into a Vector.

Xvector[i];

Error, bad index into Vector


That is why the following produces the same error
message. With Maple's usual evaluation rules for
procedure calls the argument Xvector[i] is evaluated
up front, before `i` gets any integer value.

The argument Xvector[i] gets evaluated prematurely.

Sometimes this (common) problem is referred to in Maple
as "premature evaluation".

sum(Xvector[i], i=1..3);

Error, bad index into Vector


By delaying the evaluation of the first argument until
the variable `i` gets actual integer values we can
avoid the problem.

We can delay the evaluation using single right-ticks a.k.a.
uneval-quotes.

sum('Xvector[i]', i=1..3);

6


The add command has special evaluation rules, which
delays evaluation of its first argument until `i` gets an
actual integer value.

add(Xvector[i], i=1..3);

6

This is simplest.

add(Xvector);

6

Download add_sum_Vector_indexing.mw

This relates to why the Help page for the sum command has, in its Basic Information Section, a Note: "Although the sum command can often be used to compute explicit sums, it is strongly recommended that the add command be used in programs if an explicit sum is needed, in particular, when summing over all elements of a list, Array, Matrix, or similar data structure."

There is even an example showing this very issue with sum and a Vector, in the sum,details Help page.

And lastly, that magenta error message in your Question here is a URL and you can just click it and have it open this page. You can even click on it from within the Maple GUI and have it open in your web browser. That web page includes the same sum & Vector problematic example, explanation, and two alternatives.

He might have used the Accents Palette from the GUI's expanded left-panel, with 2D Input, to get the arrow above a symbol.

If I do that (and also use the 2D Input syntax that allows for a function call on the left of an assignment to denote an operator definition),

restart

"(v)(v,theta):=<v*cos(rad(theta)),v*sin(rad(theta))>:"

"rad(theta):=theta/(180)*Pi:"

`#mover(mi("A"),mo("&rarr;"))` := `#mover(mi("v"),mo("&rarr;"))`(A, 35); `#mover(mi("B"),mo("&rarr;"))` := `#mover(mi("v"),mo("&rarr;"))`(B, -42)

Vector(2, {(1) = A*cos((7/36)*Pi), (2) = A*sin((7/36)*Pi)})

Vector[column](%id = 36893627931556680036)

Download accents_ex.mw

[edit] I'll add that using either the Accent palette as I did, or the short-cut keystrokes for an overscript following by the -> keys as Scot did, both produce the same blob of MathML-like TypeMK-thing which is a name which typesets in that desired manner.

Underneath, both construct the same specially formed name,
    `#mover(mi("v"),mo("&rarr;"))`

A variant is to use the Layout palette to insert a generic overscipt placeholder, and then the right arrow from the Arrows palette (or whatever other thing you might prefer there).

An aberration is seen for this example in Maple 2024 (and some other recent versions) with the plot command's default adaptive sampling algorithm.

In this case it utilizes plot's "new" adaptive=geometric algorithm for sampling x values, even if no choice for the adaptive option is supplied. Unfortunately that algorithm goes awry on this example. (I will submit a bug report against this example.)

By supplying the choice adaptive=true one can force the old default sampling, which works fine here.

plot(sin(x)*sqrt(1 - (sin(x)/x)^2), x = 0 .. Pi/4, adaptive=true)

 

Also, for fun,

plot(sin(x)*sqrt(1 - (sin(x)/x)^2), x = 0 .. Pi/4,
     adaptive=true,
     discont=[showremovable, symbol=solidcircle])

Are you trying to use a default numeric formatting? (Ie. a default number of digits shown for floats, units choices, etc?)

You might look at the Numeric Formatting Help page, possibly then through its link for a User Profile.

Another choice of representation is a 3D plot, of surfaces.

(You could play with the various transparency values, orientation, etc.)

restart;

kernelopts(version);

`Maple 2019.2, X86 64 LINUX, Nov 26 2019, Build ID 1435526`

K := 6; r := 3; c[1] := 1; c[2] := 1; s[1] := 5.5; s[2] := 2; q[1] := 1; q[2] := 1; p[1] := 2.5; phi[1] := .5; phi[2] := 1

eq1 := (D(x))(t) = r*x(t)*(1-x(t)/K)-q[1]*x(t)*E[1](t)/(x(t)+s[1])-q[2]*x(t)*E[2](t)/(x(t)+s[2])

eq2 := (D(E[1]))(t) = phi[1]*(p[1]*q[1]*E[1](t)*x(t)/(x(t)+s[1])-c[1]*E[1](t))

eq3 := (D(E[2]))(t) = phi[2]*(a*q[2]*E[2](t)*x(t)/(x(t)+s[2])-c[2]*E[2](t))

pdb := eq1, eq2, eq3

fcns := {x(t), E[1](t), E[2](t)}

Q := dsolve({pdb, x(0) = 1, E[1](0) = 3, E[2](0) = 1}, fcns, type = numeric, method = rkf45, maxfun = 500000, parameters = [a], output = listprocedure)

Lfun := eval(x(t), Q); Mfun := eval(E[1](t), Q); Nfun := eval(E[2](t), Q)

LE := proc (Evar::numeric, Tvar::numeric) Lfun(parameters = [':-a' = Evar]); Lfun(Tvar) end proc; ME := proc (Evar::numeric, Tvar::numeric) Mfun(parameters = [':-a' = Evar]); Mfun(Tvar) end proc; NE := proc (Evar::numeric, Tvar::numeric) Nfun(parameters = [':-a' = Evar]); Nfun(Tvar) end proc

plots:-display(
  plots:-textplot3d([1,1,18,"LE"],color=black),
  plots:-textplot3d([1,1,16,"ME"],color=red),
  plots:-textplot3d([1,1,14,"NE"],color=green),
  plot3d([LE,ME,NE],0..5,0..10,labels=["a","t",""],grid=[101,101],
         color=[black,red,green],plotlist,transparency=[0.3,0.5,0.6])
);

NULL

Download enfonction_p_2_cas1_ac.mw

You could also Explore that 3D plot (with a bit more transparency), where an `a` Slider manages construction of solid three colored spacecurves (changing `t`, for `a` fixed) that move across the three surfaces.
         enfonction_p_2_cas1_acc.mw

You can also make a regular animation from that:
         enfonction_p_2_cas1_ac_3danim.mw


ps. I've used Maple 2019, as did the OP.

3 4 5 6 7 8 9 Last Page 5 of 327