3437 Reputation

16 Badges

5 years, 230 days

MaplePrimes Activity

These are answers submitted by mmcdara

For lazzy person only

(PS: you will probably find everything you need in the Finance package; unfortunately, English not being my mother tongue and me not being at all familiar with financial terms, I used a summation to get the result. I have no doubt that if Finance has no secret for you you will find in this package the procedure that answers your question)

account_earns := 7.75/100;
years         := 30;
investment    := 4000;
add(Finance:-futurevalue(investment, account_earns, years-k), k=0..years-1)
                        4.664152587 10 

But you must have been taught how to calculate this?
Does the term Geometric_series ring any bell?

Answer to your first question

This is a simple proposal (I used Maple 2015, newer versions produces more beautiful graphs).
I did not plot a ball at the vertices, but draw the path (sequence of edges) from the root of the tree to a termibal leaf).
A ball can be drawn (as you requested) but we need do know if you just want it to be displayed when it arrives on a vertex (simple) or if you want also bo follow it along the edges (more complex).



# an example of a random tree graph

T := RandomTree(20):


Part 1: step by step explanation

# leaves (vertices of degree 1)

Leaves := map(v -> if Degree(T, v)=1 then v end if, Vertices(T)[2..-1])

[2, 4, 6, 7, 10, 11, 15, 16, 18, 19, 20]


# departure vertex

U := 1:

# random selection of the arrival leave

V := combinat:-randperm(Leaves)[1];

# shortest path from departure to arrival vertices

P := ShortestPath(T, U, V);

# coordinates of the vertices in P

X := GetVertexPositions(T)[P]



[1, 4]


[[.5000000000, 1.], [0., .8000000000]]


# parametric description of the trajectory

traj := CurveFitting:-BSplineCurve(X, t, order=1):

# The last operator (t=0..something) is to be corrected

traj := subsop(3=(t=0..numelems(P)-1), traj):

# Tree + animated path
# example

dg := DrawGraph(T):
animatecurve(traj, background=dg, color=red, thickness=3, frames=numelems(P)):

Part 2: all of this within a procedure

f := proc(T::Graph)
  local U, Leaves, V, P, X, dg, traj:
  U      := 1:
  Leaves := map(v -> if Degree(T, v)=1 then v end if, Vertices(T)[2..-1]);
  V      := combinat:-randperm(Leaves)[1];
  P      := ShortestPath(T, U, V());
  X      := GetVertexPositions(T)[P];
  traj   := CurveFitting:-BSplineCurve(X, t, order=1):
  traj   := subsop(3=(t=0..numelems(P)-1), traj):
  dg     := DrawGraph(T):
  animatecurve(traj, background=dg, color=red, thickness=3, frames=numelems(P));
end proc:






Maybe you could be interested in plotting different random paths?
Something like this....

f := proc()
  local U, Leaves, V, P, X, T2, dg, traj:
  U      := 1:
  Leaves := map(v -> if Degree(T, v)=1 then v end if, Vertices(T)[2..-1]);
  V      := combinat:-randperm(Leaves)[1];
  P      := ShortestPath(T, U, V());
  X      := GetVertexPositions(T)[P];
  traj   := CurveFitting:-BSplineCurve(X, t, order=1):
  traj   := subsop(3=(t=0..numelems(P)-1), traj):
  T2     := CopyGraph(T):
  HighlightVertex(T2, P, red); # highlight the vertices the ball hits
  dg     := DrawGraph(T2):
  display(dg, plot(traj, color=red, thickness=3, frames=numelems(P)));
end proc:

N := 10:
#animate(f, [], n=1..N, frames=N)


Once you know that your serie is the Taylor expansion of  1/(1+exp(x-5*t))^2 at t=0 (see here 232686-INFINITE-SERIES-SUM)
the answer is obvious

plot3d(1/(1+exp(x-5*t))^2, x=-10..10, t=-2..2, labels="x", "t", "u")


It's obvious that your serie can be written as a geometric serie (negative if lambda < 0, alternated if lambda > 0)

a := lambda*exp(t):
q := (-1)*lambda*(exp(t)-1):
U := (t, n) -> add(a*q^k, k=0..n):

U(t, 4);

# let's set define S(t, lambda, n) this way
S := (t, lambda, n) -> lambda*exp(t) * add(((-1)*lambda*(exp(t)-1))^k, k=0..n):

# S(t, lambda, t, n) converges iif abs(q) < 1
# assuming lambda > 0 S converges iif abs(q) < 1 that is if 0 < lambda < 1/(exp(t)-1)
# Examples

T := 2.0:
plot([seq([k, S(T, 0.95/(exp(T)-1), k)], k=1..200)]);
plot([seq([k, S(T, 1.05/(exp(T)-1), k)], k=1..200)]);

So, what is lambda?

If the serie converges its limit is 

 a * 1/(1-q);
                         lambda exp(t)     
                    1 + lambda (exp(t) - 1)

This can be obtained by elementary calculus: the sum of a (converging)  geometric serie is  limit(a*(1-q^n)/(1-q) , n=+oo) = a/(1-q) for, because of the convergence condition abs(q)<1, q^n vanishes to 0.

after the line sys := ... write

indets(sys, name);
                        {a, b, c, d, x}

You have 4 equations and you claime having 3 unknowns.
Thus you miss one (a?) ... or maybe are you looking for another type of solution (the one that would minimize some functionnal of the 4 equations?

I took the liberty to consider a is an unknown (thus x is the only input).
A numeric solution can be obtained that way.

sys := unapply(sys, x):
# example for x=1
    {a = -0.2722166549, b = -9.457425049, c = 2.635173636,  d = -3.098230243}

Is Maple able to find a formal solution of this same sys(1) system?

solve(sys(1), unknowns);

I waited about 5 minutes (Maple 2015) and couldn't get one.
So my guess is that Maple can't find a solution in terms of (here) x (alone)

Can you give the expression of the general term of this serie?
That is, if one write u(x, t)=u0(x) + u1(x)*t + ...un(x)*t^n+ ..., what is the expression of un(x)?
Or if you prefer, what is the recurrence relation between un(x) and un-1(x), un-2(x), ...un-p(x), (n>p)?

If we take the problem from the other side, one observe that the taylor expansion of u(x,t) with respect to t has its first terms equal to the first ones of the serie you give.

u := 1/(1+exp(x-5*t))^2:
S := map(simplify, taylor(u, t))

Of course it's easy do to what I'm going to do once we accept the previous result.

  • the coefficients of the successive terms are 10, 50/2, 250/6, 1250/24, ...
    thus terms of the form 10 * 5^k / k! with k=0..+oo
  • this suggest that the serie could be a Taylor expansion of some function w(x, t)
    moreover, giving the expression of the terms that contain t, this Taylor expansion, which should contain terms like (t-a)^k can be done at a=0
  • for k=0 one has w(x, 0) = f(x) = 1/(1+exp(x))^2.
    let us observe a few derivatives of f(x) with respect to x:
    f := (1/(1+exp(x))^2:
    print~([seq(simplify(eval(diff(f, [x$k]), t=0)), k=0..5)]):
    we observe that these derivative are equal, up to a miltiplicative constant, to the terms that contain x in your serie
  • if w(x, t) is of the form w(x+c*t), it's easy to see that 
    # set z=x+c*t
    diff(w(x+c*t), t$k) = diff(w(z), z$k)*c^k
    this could lead to the inference that your serie is the Taylor expansion (1/(1+exp(x+c*t))^2 around t=0
  • under this hypothesis one easily finds that c=5

If the assumption that your serie is such a Taylor expansion, it converges for any real values of x and t.



e := L/(z*sqrt(z^2 + L^2))


# case L >> z
# set L=a*z with a >> 1

eval(e, L=a*z);
numer(%)/z / simplify(denom(%)/z) assuming z > 0;
eval(%, a=L/z);

asympt(%, L, 2):
expand(simplify(%)) assuming z > 0






# case z >> L
# set z=a*L with a >> 1

eval(e, z=a*L);
numer(%)/L / simplify(denom(%)/L) assuming L > 0;
eval(%, a=z/L);
asympt(%, z, 4):
expand(simplify(%)) assuming L > 0









One way with geom3d package




# first line

plane(P1, 16*x-2*y-11*z, [x,y,z]):
plane(P2, 14*x-y-10*z-3, [x,y,z]):
line(L1, [P1,P2]):
Param_Eq__1 := Equation(L1,'t');
                    [1                     ]
                    [- + 9 t, 4 + 6 t, 12 t]
                    [2                     ]
# second line (=L2)
# let u be the common value of (x-2)/3, (y-5)/2 and (z-2)/4

X := solve((x-2)/3=u, x);
Y := solve((y-5)/2=u, y);
Z := solve((z-2)/4=u, z);
r := u=solve(X=rhs(Param_Eq__1[1]), u);
eval([X, Y, Z], r)
                         u = - - + 3 t
              [1                     ]
              [- + 9 t, 4 + 6 t, 12 t]
              [2                     ]

Thus lines L1 and L2 are  identical.

First problem only (I'm going to bed)

Step 1: define M and N this way

M := (a, b) -> (a+b)/2;
N := (a, b) -> a*b/M(a, b);


Step 2: the recurrence is

a(n+1) = M(a(n), b(n)),  b(n+1) = N(a(n), b(n))

Set  z(n+1) = a(n+1) * b(n+1) and observe that z is invariant under the transformations M and N.

z(n+1) = a(n+1) *  b(n+1) = a(n) * b(n) = ... = a(0) * b(0)

Step 3 : find a limit (aka stationary) solution by solving this system of equations (could be done by hand)

solve({M(x,y)=x, N(x, y)=y})
                         {x = y, y = y}

Thus a stationary solution is such that x=y (or limit(a(n), n=+oo) =  limit(b(n), n=+oo) if you prefer

Step 4 : inject this stationary solution within z : 
As limit(a(n), n=+oo) =  limit(b(n), n=+oo), one gets limit(z(n), n=+oo) = z(0) = a(0)*b(0) and thus 

limit(a(n), n=+infinity) = limit(b(n), n=+infinity) = sqrt(a(0)*b(0))

Example : a(0)=1 and b(0)=2 gives  limit(a(n), n=+oo) =  limit(b(n), n=+oo) = sqrt(2)



Does this suit you?

(u instead of u(y))

alias(u=u(y, z));
de := diff(u, y$2)+3*delta*diff(u, y)^2*diff(u, y$2)=p;

# and for subsequent computations
eval(de, u=U(y));
# example
dsolve(%, U(y));

Note that the trick alias(u(y)=u(y, z)) won't produce the desired result

It seems odd to want to create a diagonal system but you probably have your own reasons.
Here is a possibility

Standard Worksheet Interface, Maple 2015.2 ....


A := (z, M) -> DiagonalMatrix([z$M]):
V := (n, M) -> Vector(M, i -> u[i, n]):

# example of use,
# the neutral operator &. to avoid the evaluation of the matrix vector product

A(omega[2]*(2-b[1]), 3) &. V(2, 3);

# your question:
N := 4:
m := 3:

for j from 2 while j <= N do
   printf("%s j = %d %s\n", cat("-"$50), j, cat("-"$50));
   A(omega[2]*(2-b[1]), m) &. V(j, m)
   A(2*b[1]*omega[2]-b[2]*omega[2]-omega[2]+1, m) &. V(j-1, m)
   (sum(A(omega[2]*(b[l+2]-2*b[l+1]+b[l]), m) &. V(j-l-1, m), l = 1 .. j-2))
end do;

REVISED 2021/8/06
A revised version inspired by  the answer acer made to this question 232636-Is-It-Possible-To-Construct-Binary-Operators

Your parameterization seems to be too complex for Maple to be able to handle the assumptions.
I suggest you to use this one

assume(s < t, t < 0, 0 < u, u < v);
r := x -> piecewise(
            s <= x and x <= t, b*(1 -((t-x)/(t-s))^(2)),  
            t <  x and x <  u, b,  
            u <= x and x <= v, b*(1- ((x-u)/(v-u))^(2))

Where s, t, u and v correspond to

  • s -->  -a
  • t -->  -a + epsilon
  • u --> +a - varepsilon
  • v --> +a

See in the attached file

PS: I thought you caps where ellipses with half small axes equal to epsilon or varepsilon (depending if they cap the left or the right section of the cylinder) and half great axes equal to b?
This not the case xith what you did (the tangents to the elliptic cap at x=s or x=v are not vertical.
Maybe you wanted this?

r := x -> piecewise(
            s <= x and x <= t, b*sqrt(1 -((t-x)/(t-s))^(2)),  
            t <  x and x <  u, b,  
            u <= x and x <= v, b*sqrt(1- ((x-u)/(v-u))^(2))

LAST POINT: since you mentioned cylinder, I don't know if you are aware of the SurfaceOfRevolution  function?
If not you might like this

Student:-Calculus1:-SurfaceOfRevolution(eval(r(x), [s=-3, t=-2, u=2, v=3.5, b=2]), x=-3..3.5, output=plot, scaling=constrained);


To avoid the errors just change v__2p := 0.0 into v2p := 0*Unit(('m')/('s'));

I think you might also like v__1k and v_2k  to be expressed with their units (m/s)?
In such a case here is a solution

m__2 := .4*Unit('kg');
m__1 := .3*Unit('kg');
x__w := .7*Unit('m');
v__2p := 0.*Unit('m'/'s');
v__1p := 2*Unit('m'/'s');

pot := m__1*v__1p+m__2*v__2p = m__1*v__1k+m__2*v__2k;
kin := (1/2)*m__1*v__1p^2+(1/2)*m__2*v__2p^2 = (1/2)*m__1*v__1k^2+(1/2)*m__1*v__2k^2;

solve([pot, kin], [v__1k, v__2k])


Here is a solution: at the end of uor code you can include this (see the attached file for a complete worksheet)

start := StringTools:-Ord("A");
letters := StringTools:-Char~([$start..start+25])

_iquo := iquo(n, 26):
_irem := irem(n, 26):

if n <= 26 then 
  LETTERS := letters[1..n]
  LETTERS := letters[]:
  for i from 2 to _iquo do
    LETTERS := LETTERS, cat~(letters, i-1)[]
  end do:
  LETTERS := LETTERS, cat~(letters[1.._irem], _iquo)[]
end if:

newlist       := [LETTERS] =~ z;            # elements of the form "A2"=[1, 2]
other_newlist := parse~([LETTERS]) =~ z     # elements of the form A2 =[1, 2]

REMARK : there is no real assignment here in the sense of ?assign.
The reason is that some "letters" such as D, I, O are protected, so you can't assign them unless unless you define them as local  (which could be dangerous).
An example is provided at the end of the attached file

Simple reasoning:
I assume that all the points have integer coordinates (right?) and that mov1ng from A to B means "always move in the same horizontal direction and in the same vertical direction" (if it's not the case a pathh from A to B can have an infinite length).
More of this I understand that you want to go from A to E by going fromA to B, next from B to E and so on (right?).
If I'm wrong on this last point a minor modification of what I'm going to say can be derived to find a shorter path that visit all the points once/

Let (xA, yA) the coordinates of A and (xB, yB) those of B.
Let  xm=min(xA, xB), xM=max(xA, xB), ym=min(yA, yB), yM=max(yA, yB).
Let hx = xM-xand hy = yM-ym.
Note that hx  and hy  are 2 integers; thus there exist exactly  C(hx+hy, hy) = (hx+hy)!/(hx!*hy!) paths from A to B that have all the same length hx + hy .
Once arrived at B, do exactly the same thing to determine the number of paths from B to C and their length
(which is just abs(xC-xB)+abs(yC-yB))

Thus the length of any of all the paths from A to E is equal to 
abs(xB-xA)+abs(yB-yA) + .... + abs(xE-xD)+abs(yE-yD
There exist exactly C(abs(xB-xA)+abs(yB-yA), abs(yB-yA)) * ... * C(abs(xE-xD)+abs(yE-yD), abs(yE-yD)) such paths

For instance, if A=(0,0) and B = (2, 3), there exist 6 paths ((2+3)!/2!/3!) of length 5 (X denote a move of length in the horizontal direction and Y a move of length 1 in the vertical direction)
X Y X Y Y 
Y X X Y Y 
Y X Y Y X 

For the graph you give there are:

  • 2 paths of length 2 from A to B
  • 5 paths of length 5 from B to C
  • 10 paths of lrngth 5 from C to D
  • 2 paths of length 2 from D to E

and thus 200 shortest paths of length 14 of the form A->B->C->D->E

Note that the paths of type A->B->D->E->C have length 13 (see above my second assumption).

In case you want to find a cycle which passes from all the points (not a path), which means the ending point is also the starting point, it's bovious to see that the shortest cycle is A->B->D->E->C->A (3360 such cycles if we do not account for the starting point) with length 20

PS:the distance you refer to is the Mahalanobis distance, also dubbed the "taxi distance" by reference to the path a taxi takes in New York downton where streets are either pairwise parallel or orthogonal.

5 6 7 8 9 10 11 Last Page 7 of 28