Carl Love

## 25000 Reputation

10 years, 167 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

## Need c such that integral = 1...

The links to your uploaded worksheets are not working. But the idea of the problem is that the integral of f(x) from 0 to c must equal 1.

eqn:= int(x^2/9, x= 0..c) = 1;
solve({eqn, c>0}, c);

See ?intsolve.

## indets...

One problem with using index numbers with op is that you don't know that the integral will be the, say, 3rd factor in each term. Indeed, the ordering of the factors within each term might change on different runs. If you just want to extract all the integrals from lhs(eq10_1), then do

indets(lhs(eq10_1), specfunc(anything, Int));

If you want to extract the integrals and maintain the order that they have in the equation (and you know that there is more than one term and at most one integral per term), then do

map(op@indets, [op](lhs(eq10_1)), specfunc(anything, Int));

## pixelation?...

I believe that the effect that you're seeing is just due to the pixel size of your screen, and has nothing to do with the number of points. Curves that are close to horizontal or close to vertical will appear jagged. We have to live with it until they start making screens at 300 dots per inch, or more. Try printing the plot on paper and seeing if the effect is still present.

## In three short lines...

In three short lines:

 > R1:= %cos ~ (< 1|1|1 >*omega*t + 2*Pi/3*<0|-1|1>):
 > T:= sqrt(2/3)*value(< R1, eval(R1, %cos= -%sin), < 1|1|1 >/sqrt(2) >):
 > (simplify@expand) ~ (T.map(diff, T, t)^%T); >

## Histogram used as stem and leaf plot...

I think that a properly constructed histogram would be a better-than-the-original substitute for a stem-and-leaf plot. What do think of this (the gridlines don't appear in the worksheet; that's an artifact of MaplePrimes)?

 > restart;
 > Data:= [130.8, 129.9, 131.5, 131.2, 129.5, 132.2, 133.7, 127.8, 131.5, 132.7, 134.8, 131.7, 133.9, 129.8, 131.4, 132.8,  132.7, 128.8, 130.6, 131.1, 133.8, 130.5, 131.4, 131.3, 129.5 ]:
 > Statistics:-Histogram(    Data   ,binbounds= [\$127..135]   ,frequencyscale= absolute   ,axis= [tickmarks= [.5 +~ [\$127..134] =~ [\$127..134]]] ); > Quartiles = map2(Statistics:-Quartile, Data, [1,2,3]); >

## Need to separate params and ICs...

You need to separate the parameter definitions from the setting of the initial conditions. A clean way to do this is

eq1 := {
diff(S_h(t),t)= mu_h*(N_h-S_h(t))-(bi_h*b)/(N_h+m)*S_h(t)*I_v(t),
diff(I_h(t),t)=(bi_h*b)/(N_h+m)*S_h(t)*I_v(t)-(mu_h+ga)*I_h(t),
diff(R_h(t),t)=ga*I_h(t)-mu_h*R_h(t),
diff(S_v(t),t)=A-(bi_v*b)/(N_h+m)*S_h(t)*I_h(t)-mu_v*S_v(t),
diff(I_v(t),t)=(bi_v*b)/(N_h+m)*S_v(t)*I_h(t)-mu_h*I_h(t)
};
params:= {
mu_h=0.0000457,mu_v=0.25,b=1,ga=0.167,
bi_h=0.4, bi_v=0.4,m=0,N_h=10000,A=5000
};
ICs:= {
S_h(0)=10000, I_h(0)=1,R_h(0)=0,S_v(0)=10000,I_v(0)=1
};

sol1:=dsolve(
eval(eq1, params) union ICs,
{S_h(t),I_h(t),R_h(t),S_v(t),I_v(t)},
type=numeric
);

## "uses" clause...

Go to ?procedure and read about the uses clause of a procedure header. You can't use with inside a procedure, and I'd recommend against writing procedures that rely on a with performed outside the procedure. With the uses clause, you can make abbreviations:

proc()
uses St= Statistics, LA= LinearAlgebra;
local A,B, ...;
...;
A:= St:-Rank(...);
B:= LA:-Rank(...);
...
end proc;

Also, my opinion is that A:-B looks more elegant than A[B]. Maple already has enough square brackets; it is nice to balance the variety of symbols.

## A tensor product...

(A prior version of this answer was messed up due to the well-known bug of the MaplePrimes editor dropping angle brackets.)

The below assumes that the factors are represented as 2x4 Matrices, and it represents the product as a 4x4 Matrix.

 > `&x`:= proc(AB::Matrix(2,4), CD::Matrix(2,4))    local C:= CD[.., 1..2], D:= CD[.., 3..4];    < < AB[1,1]*C + AB[1,3]*D | AB[1,2]*C + AB[1,4]*D >,      < AB[2,1]*C + AB[2,3]*D | AB[2,2]*C + AB[2,4]*D >    > end proc:

Example of use:

 > A,B,C,E:= seq(LinearAlgebra:-RandomMatrix(2, 2, generator= rand(-1..1)), k= 1..4); > '`&x`'('`<|>`'(A,B), '`<|>`'(C,E)) = < A|B > &x < C|E >;  ## ToInert and dismantle...

Check out ?ToInert and ?dismantle. The former returns a result that is logically identical to what you want; it is just not presented visually as a tree. The latter displays the output in tree form, but includes details that you might find irrelevant. It would be relatively easy to convert the ToInert output to an explicitly presented tree by using the GraphTheory package and its DrawNetwork command.

Example:

ToInert(x+2*y*z^2); ## How to use plottools:-transform...

Excellent questions, TomM. There is no bug, but the answers to your questions are very poorly documented, if documented at all. It took me several hours on 17-Jan-2013 to figure out the answers to those same questions.

TomM wrote:

On Maple 16.02, plattools[transform] only works for very simple procedures. It does not work for procedures  with the `if` function even with the simple arrow definition. or with any if-block in a more general proc definition.

You can use procedures of arbitrary complexity, but it requires a little trick at the beginning of the procedure. Let's call the procedure which is passed to plottools:-transform "the point transformer", and let's call the procedure that plottools:-transform returns "the plot transformer".  When the plot transformer is called, the first call that it makes to the point transformer will be with symbolic (i.e. non-numeric) arguments. It does this to check the number of dimensions returned (because plottools:-transform can be used to transform 2D to 3D and vice versa). On this first call, the point transformer must return a list (or other object) with the correct number of elements.

TomM wrote:

simp:= plot(sin(x), x= 0..Pi);
f:=(xx,yy)->`if`(yy > 0, [xx,4*yy], [xx,yy]);
trns:=plottools:-transform(f);
trns(simp);

So, for the above, your point transformer should be written:

f:=(xx,yy)-> `if`(not (xx::numeric and yy::numeric), [xx,yy], `if`(yy > 0, [xx,4*yy], [xx,yy]));

For an example of a much more complex point transformer, see my MaplePrimes post BubblePlot plotting view: Modification so that the axes don't change.

TomM wrote:

From examining op(trns), the error seems to occur in the procedure: `transform/object`. However, I cannot find a way to print out this procedure, even with verboseproc=2, with print or op. Where is this procedure, and how can I print it out?

It is a procedure local to module plottools. So, to print it out, do

interface(verboseproc= 2);
eval(plottools:-`transform/object`);

You can also showstat that procedure, or trace it; which is how I figured out the answer to your first problem.

TomM wrote:

On the other hand, with f:=(xx,yy)-> [xx, 3*max(0,yy)+yy], the transform works and produces the same plot as the non-working sequence above.

It works because the above f will return a list of two elements even if it is passed symbolic arguments. But if it was inside an `if`, then it would just return the unevaluated `if`, which is not a list, and doesn't have two elements.

## Tangent plots...

P:= n-> plot([x^2,2*x-1], x= 1-.1^n..1+.1^n):
plots:-display(<P(0)|P(1)|P(2)>);

## First baby steps in large-scale debuggin...

You can take some first baby steps towards debugging thus:

kernelopts(opaquemodules= false);
interface(verboseproc= 3);
trace(RegularChains:-TRDisolate_real_zeros);
showstat(RegularChains:-TRDisolate_real_zeros);
printlevel:= 2;

And then run your command. But it gets deep rather quick: RegularChains has 1381 local procedures---the most I've ever seen---all of whose names begin TRD.

## List arithmetic...

For lists G and K, it can be done with elementwise operators thus:

Ga := Basis({(a*~G)[], ((1-a)*~K)[]}, 'tord', deglex(a,r,u,v,w));

## More unknowns than equations...

The problem is that you have more unknowns than equations. You should look at the output instead of ending every command with a colon. Using N=3, M=3, I get 12 "U" variables and only 6 equations in Eqs1. I think you might need to incorporate some BCs into the equations, but I can't help you much with that. You also might have a problem with index numbers.

﻿