Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 356 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

The following procedure computes the sequence. However, I don't get the values that you propose. For example, how do you get 2, not 4, as the second entry?

A:= proc(n::posint)
option remember;
local A0; #A(n-1)
   if n=1 then return 1 fi;
   A0:= thisproc(n-1);
   `if`(A0::even, `if`((A0+1)::prime, A0+1, n+2), A0+3)
end proc
:
seq(A(n), n= 1..20);
1, 4, 5, 8, 10, 11, 14, 16, 17, 20, 22, 23, 26, 28, 29, 32, 34, 36, 37, 40

 

The name Zeta is already defined in Maple (for the Riemann-Hurwitz zeta function), so it's dangerous to use it as a variable. You should replace it with zeta, which'll prettyprint identically to Zeta as the lowercase.

Once you make that change, then all you need to do is

evalc(%)

The evalc automatically assumes that all variables are real, thus avoiding some of the complexity of the other Answers. But it won't assume that Zeta is real because that's already defined and is thus not a free variable.
 

If you'd prefer to continue using Zeta, you could do

local Zeta;

and it'll now be a totally free variable. If perchance you'd still like to use the Riemann-Hurwitz zeta function, you can call it with :-Zeta(...), and now the names Zeta and :-Zeta will not have any link to one another.

 

You can use lhs and rhs to operate on specific sides of equations. You can use rcurry to pass trailing arguments to operators. So, what you ask for can been done as

(lhs = rcurry(int, T[1])@rhs)(%)

I can't say whether it's "the right thing to do."

It wasn't removed. It was branched into a separate Question (entitled "Algorithms") for which your Comment became an Answer. The branching wasn't done by me, although I do agree with the editorial decision to do so. I converted the branch from a Post to a Question, converted your Comment to an Answer, and voted it up. Any Moderator can do these things; it wasn't VV.

Instead of 

pdsolve(PDE, IBC, ...)

use 

pdsolve(PDE, {IBC}, ...)

This will correct that error that you're currently facing. I'm not necessarily saying that this will get you to the final result.

There is no need to fully factorize the numbers. If the part that remains after factoring out all 2s, 3s, 5s, 7s, and 11s is greater than 1, then the number must have a prime factor greater than 11. Thus, the following code is much faster than the other Answers that call ifactor or ifactors:

QuoP:= proc(n,p)
local q:= n, q1;
   do if irem(q,p,'q1')=0 then q:= q1 else return q fi od
end proc
:  
QuoPs:= proc(n)
local q:= n, p;
   for p in [2, 3, 5, 7, 11] while q <> 1 do q:= QuoP(q,p) od;
   q
end proc
:
Check:= proc(n)
local k;
   for k from n to n+3 do if QuoPs(k) <> 1 then return true fi od;
   false
end proc
:

 

Using certain reasonably simple yet also reasonably general assumptions, that expression simplifies to 0. By eye, I see that a >= 0, b >= 0, z >= 0 are sufficient conditions. These are not necessarily necessary conditions, just an example of what I see immediately as sufficient. I think that the point being made by pdetest (a point supported by its documentation) is that the pde solution is only guaranteed to be valid under certain assumptions.

The local command can be used at the top level. So, all you need to do is

local gamma;

Your transition matrix P is a patterned tridiagonal or band matrix. It can be constructed with a single-line Matrix command using the scan= band option.

I can see no practical value to storing the positive integer powers of this matrix, so I haven't done that. You might as well simply recompute the powers as needed.
 

restart:

Digits:= 15:

N:= 2:  dimP:= 2*N+1:  m:= dimP-2:

(q,p):= (0.3,0.5):  r:= 1-p-q:  sa:= 0.9:  sb:= 1-sa:

P:= Matrix([[q$m, sa], [sa, r$m, sb], [sb, p$m]], scan= band[1,1]);

Matrix(5, 5, {(1, 1) = .9, (1, 2) = .1, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (2, 1) = .3, (2, 2) = .2, (2, 3) = .5, (2, 4) = 0, (2, 5) = 0, (3, 1) = 0, (3, 2) = .3, (3, 3) = .2, (3, 4) = .5, (3, 5) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = .3, (4, 4) = .2, (4, 5) = .5, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = .9, (5, 5) = .1})

The matrix is stochastic with no entry equal to 1. The theory of Markov chains says that there is a stochastic vector s such that s.P = s. All rows of P^n approach this s as n approaches infinity. Here are two methods to compute s.

 

Method 1: Eigenvectors:

The equation s.P = s means that s is a left eigenvector of P for eigenvalue 1. So the transpose of s is a right eigenvector of the transpose of P. The transpose of a matrix or vector is denoted in Maple by appending ^+.

(e,V):= LinearAlgebra:-Eigenvectors(P^+):

Find the position of 1 among the eigenvalues and call the position p1.

member(1,e,p1);

true

Extract the corresponding eigenvector and transpose it.

s:= V[..,p1]^+;

Vector[row](5, {(1) = -.627245607666573+0.*I, (2) = -.20908186922219074+0.*I, (3) = -.34846978203698503+0.*I, (4) = -.5807829700616427+0.*I, (5) = -.32265720558980143+0.*I})

The zero imaginary parts can be removed by simplify:

s:= simplify(s);

Vector[row](5, {(1) = -.627245607666573, (2) = -.209081869222191, (3) = -.348469782036985, (4) = -.580782970061643, (5) = -.322657205589801})

Convert to a stochastic vector by normalizing with respect to the 1-norm:

s:= s*csgn(s[1])/LinearAlgebra:-Norm(s,1);

Vector[row](5, {(1) = .30037082818294236, (2) = .10012360939431413, (3) = .16687268232385685, (4) = .2781211372064288, (5) = .15451174289246009})

Compare with a high power of P:

P^999;

Matrix(5, 5, {(1, 1) = .30037082818294697, (1, 2) = .10012360939431567, (1, 3) = .16687268232385943, (1, 4) = .27812113720643244, (1, 5) = .15451174289246247, (2, 1) = .30037082818294686, (2, 2) = .10012360939431565, (2, 3) = .1668726823238594, (2, 4) = .27812113720643233, (2, 5) = .15451174289246242, (3, 1) = .30037082818294686, (3, 2) = .10012360939431565, (3, 3) = .16687268232385938, (3, 4) = .27812113720643233, (3, 5) = .15451174289246242, (4, 1) = .30037082818294686, (4, 2) = .10012360939431565, (4, 3) = .1668726823238594, (4, 4) = .27812113720643233, (4, 5) = .15451174289246242, (5, 1) = .30037082818294686, (5, 2) = .10012360939431564, (5, 3) = .1668726823238594, (5, 4) = .27812113720643233, (5, 5) = .15451174289246242})

Method 2: System of linear equations:

Solving the system s.P = s for s is equivalent to solving (P^+ - I).s^+ = 0 (where I is the identity matrix). This system is of course singular. We fix that by adding the condition that s be a stochastic vector.

LinearAlgebra:-LinearSolve(
  <P^+-Matrix(dimP, shape= identity), <seq(1, 1..dimP)>^+>,
  <seq(0, 1..dimP), 1>
)^+;

Vector[row](5, {(1) = .30037082818294225, (2) = .10012360939431397, (3) = .16687268232385655, (4) = .2781211372064275, (5) = .15451174289245972})

 


 

Download TransitionMatrix.mw

I think that you have enough sophistication and experience with a variety of languages[*1] to realize that any statement of the form "ASCII string X and ASCII string Y mean exactly the same thing in computer language L, which is abstract mathematical object M" is ontologically problematic. The level of evaluation (parser, automatic simplifier, etc.) needs to be considered. For your example, lprint (among numerous possible evaluations) reveals that they're not the same thing at the default level of evaluation. 

The only form of derivative for initial and boundary conditions containing derivatives that's consistently supported by the documentation is D. If some component accepts another form, that's merely grace (to use Preben's word) or a bonus (to use Vv's word). So it's only at the highest level of evaluation---inside the mind of the programmer---that they could be considered equal.

[*1]Judging by your 752 postings on MaplePrimes, every word of which I've read.

If LL is your list of lists, then the list of the averages of the sublists can computed by (add/nops)~(LL). This works for both symbolic and numeric data. 

You can't meaningfully assign values to both a name and an indexed form of the same name. In this case, you've done this with and r[1] and and k[1]. You can avoid this problem while still having the prettyprinted form of the index appear as a subscript by using r__1. If you don't care about whether the index appears as a subscript, you can use and r1.

There is no problem with assigning to multiple indexed forms of the same main name as long as you don't assign to the main stem. For example, you can assign to r[0] and r[1] as long as you don't assign to r.

The command that you're trying to use, ExpandSteps, is only for polynomial expansion, not for matrix arithmetic. The command that applies to your situation is Student:-LinearAlgebra:-GaussJordanEliminationTutor; however, its use is limited to matrices at most 5 x 5.

I see that your matrix has 9-digit exact integers and exact imaginary values. So what's the point of seeing the steps? Do you suspect an error in Maple's computation?

Maple handles regular expressions. See these help pages:

  • ?StringTools,Regular_Expressions
  • ?StringTools,RegMatch
  • ?StringTools,RegSplit
  • ?StringTools,RegSub
  • ?StringTools,RegSubs

All that VV said is true. I'd just like to add that if you want symbolic variables to be treated like would-be integers until they have values assigned, then use irem instead of mod.

First 142 143 144 145 146 147 148 Last Page 144 of 395