mmcdara

7002 Reputation

18 Badges

8 years, 224 days

MaplePrimes Activity


These are answers submitted by mmcdara

restart

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

sl10 :=  -1 <= (3-5*x)*(1/2) and (3-5*x)*(1/2) <= 9

0 <= 5/2-(5/2)*x and -(5/2)*x <= 15/2

(2)

sol_1 := solve(sl10)

RealRange(-3, 1)

(3)

convert(x in sol_1, relation)

And(-3 <= x, x <= 1)

(4)

sol_2 := solve({op(sl10)})

{-3 <= x, x <= 1}

(5)

simplify(And(op(sol_2)))

And(-3 <= x, x <= 1)

(6)

# Or use what I proposed you here


Download examples.mw

Technically f is a number and writing diff(f, something) is identically null.

Don't you mean "what is the variation delta(f) of f given a variation delta(q) of function q" ?

Look to this, maybe that will help you (or not)

variation.mw

The key code is 

# N = numelems(team):
# n = number of teammates per set
# T = list of sets lists

T := [seq(team[1+(i-1)*n..i*n], i=1..N/n)]:

restart

 

new_team := ["Michael K", "Andy C", "Michael G", "Mitch", "Jez", "Dean B", "Anthony B", "Rik B", "Ilya", "Fariborz", "Eugene", "Tania", "Bill", "Stevs", "Victor", "Jane", "Nash", "Ben"]:

 

MakeTeams := proc(team, n)
  local N, T, i, k, fmt;
  N := numelems(team):
  if irem(N, n) <> 0 then
    error cat("The number of players (", N, ") is not a multiple of the number (", n, ") of team members")
  end if:
  T := [seq(team[1+(i-1)*n..i*n], i=1..N/n)]:

  k   := numelems(convert(N/n, base, 10)):
  fmt := cat("set %", k, "d: %a\n"):
  for i from 1 to N/n do
    printf(fmt, i, T[i])
  end do:

  return T
end proc:

MakeTeams(new_team, 2):

set 1: ["Michael K", "Andy C"]
set 2: ["Michael G", "Mitch"]
set 3: ["Jez", "Dean B"]
set 4: ["Anthony B", "Rik B"]
set 5: ["Ilya", "Fariborz"]
set 6: ["Eugene", "Tania"]
set 7: ["Bill", "Stevs"]
set 8: ["Victor", "Jane"]
set 9: ["Nash", "Ben"]

 

 

newnew_team := ["Michael K", "Andy C", "Michael G", "Mitch", "Jez", "Dean B", "Anthony B", "Rik B", "Ilya", "Fariborz", "Eugene", "Tania", "Bill", "Stevs", "Victor", "Jane", "Nash", "Ben", "Malachi T", "R", "Sachin ", "Prakash Sn", "Graeme", "Nayu", "Martih", "Rickn", "Ahmed"]:

MakeTeams(newnew_team, 3):

set 1: ["Michael K", "Andy C", "Michael G"]

set 2: ["Mitch", "Jez", "Dean B"]
set 3: ["Anthony B", "Rik B", "Ilya"]
set 4: ["Fariborz", "Eugene", "Tania"]
set 5: ["Bill", "Stevs", "Victor"]
set 6: ["Jane", "Nash", "Ben"]
set 7: ["Malachi T", "R", "Sachin "]
set 8: ["Prakash Sn", "Graeme", "Nayu"]
set 9: ["Martih", "Rickn", "Ahmed"]

 


printf variant

MakeTeams_bis := proc(team, n)
  local N, T, i, k, fmt;
  N := numelems(team):
  if irem(N, n) <> 0 then
    error cat("The number of players (", N, ") is not a multiple of the number (", n, ") of team members")
  end if:
  T := [seq(team[1+(i-1)*n..i*n], i=1..N/n)]:

  k   := numelems(convert(N/n, base, 10)):
  fmt := cat("set %", k, "d: ", seq("%s, ", i=1..n-1), "%s\n");
  for i from 1 to N/n do
    printf(fmt, i, op(T[i]))
  end do:
  return T
end proc:

MakeTeams_bis(new_team, 2):
print():
MakeTeams_bis(newnew_team, 3):

set 1: Michael K, Andy C
set 2: Michael G, Mitch

set 3: Jez, Dean B
set 4: Anthony B, Rik B
set 5: Ilya, Fariborz
set 6: Eugene, Tania
set 7: Bill, Stevs
set 8: Victor, Jane
set 9: Nash, Ben

 

 

set 1: Michael K, Andy C, Michael G
set 2: Mitch, Jez, Dean B
set 3: Anthony B, Rik B, Ilya
set 4: Fariborz, Eugene, Tania
set 5: Bill, Stevs, Victor
set 6: Jane, Nash, Ben
set 7: Malachi T, R, Sachin
set 8: Prakash Sn, Graeme, Nayu
set 9: Martih, Rickn, Ahmed

 

`&rsquo;`

(1)


You can also build random teams this way

MakeRandomTeams := proc(TEAM, n)
  local team, N, T, i, k, fmt;
  team := combinat:-randperm(TEAM);
  N := numelems(team):
  if irem(N, n) <> 0 then
    error cat("The number of players (", N, ") is not a multiple of the number (", n, ") of team members")
  end if:
  T := [seq(team[1+(i-1)*n..i*n], i=1..N/n)]:

  k   := numelems(convert(N/n, base, 10)):
  fmt := cat("set %", k, "d: %a\n"):
  for i from 1 to N/n do
    printf(fmt, i, T[i])
  end do:
  return T
end proc:

MakeRandomTeams(new_team, 2):

set 1: ["Michael G", "Andy C"]
set 2: ["Nash", "Ilya"]
set 3: ["Anthony B", "Bill"]
set 4: ["Tania", "Stevs"]
set 5: ["Michael K", "Mitch"]
set 6: ["Rik B", "Victor"]
set 7: ["Dean B", "Jez"]
set 8: ["Ben", "Jane"]
set 9: ["Eugene", "Fariborz"]

 
 

 

Download teams_mmcdara.mw

x in RealRange(1, Open(4)):
convert(%, relation)
                    1 <= x < 4

If you realy want to get a single inequality when the interval contains +/- infinity you can use procedure rel below: 

rel := proc(RR)
  local r := convert(RR, relation);
  if has(r, infinity) then
    r := remove(has, [op(r)], infinity)[]
  end if:
  r
end proc:

RR := x in RealRange(1, Open(4));
rel(RR)

`in`(x, RealRange(1, Open(4)))

 

And(1 <= x, x < 4)

(1)

RR := x in RealRange(Open(2), Open(infinity));
rel(RR)

`in`(x, RealRange(Open(2), infinity))

 

2 < x

(2)

RR := x in RealRange(Open(-infinity), Open(-3));
rel(RR)

`in`(x, RealRange(-infinity, Open(-3)))

 

x < -3

(3)

RR := x in RealRange(2, 3);
rel(RR)

`in`(x, RealRange(2, 3))

 

And(2 <= x, x <= 3)

(4)
 

 

Download Enhanced_convert.mw

 

 

restart
f := X^2 + Y^2 - 1:
g := X - Y:
intersections := proc(P, Q, T)
  local ind, R, W, w:

  # check
  ind := indets({P, Q}):
  if not member(T, ind) then
    error cat(sprintf("%s%", T), " is not an indeterminate of {P, Q}")
  elif numelems(ind) = 1 then
    error cat("Only one indeterminate ", sprintf("%s%", op(ind)), " found, 2 needed")
  elif numelems(ind) > 2 then
    error "More than 2 indeterminates found: P and/or Q do not define plane curves"
  end if:

  R := resultant(P, Q, T);
  W := op(ind minus {T});
  
  w := solve(R, W);

  return W = {w}
end proc:
intersections(f, g, X)
                        /  1  (1/2)  1  (1/2)\ 
                  Y =  { - - 2     , - 2      }
                        \  2         2       / 

intersections(f, g, A)
Error, (in intersections) A is not an indeterminate of {P, Q}
intersections(f+A, g, X)
Error, (in intersections) More than 2 indeterminates found: P and/or Q do not define plane curves
intersections(X, X^2, X)
Error, (in intersections) Only one indeterminate X found, 2 needed


Note that
 

solve({f, g}):
allvalues(%);
 /    1  (1/2)      1  (1/2)\            /      1  (1/2)        1  (1/2)\ 
{ X = - 2     , Y = - 2      }    ,     { X = - - 2     , Y = - - 2      }
 \    2             2       /            \      2               2       / 

numelems([%])
                 2


Note: I don't know if you got this code from Mistral AI as you often does, but it's worth saying that a lot of Artificial Intelligences give stupid results specially when used blindly or not trained properly


@GFY @acer

@acer's answer is great, but here is another wayto answer your problem which seems to me more natural (IMO).

The idea is still to use events but in conjunction with option discrete_variables. (see the event help page for more details).
Basically one augment the differential system by two functions A(t) and B(t) (the "discrete variables", not defined from differential equations), each of them being aimed to represent one of the two envelopes.
Specific events are used to build A(t) and B(t).

odeplot can be used directly in the usual way to plot those functions, for instance:

odeplot(solu12, [t, A(t)], t=...)

saopinjifen1230_mmcdara.mw

It is worth mentioning that the computation time for dsolve (without range option) is 0.1 sec and that it takes only 2.5 sec to odeplot the result (40 times faster than @acer's solution).

Note that using the range option and the refine option in odeplot (which can be useful for a better representation of x(t) only) can dramatically increase these times.


Successive-zooms.pdf

As you see below (first figure)  A(t) and B(t), excepted for the early times, are stepwise functions.
This is different from what @acer gets (second figure)

 



Note that it would quite simple to transform "my" stepwise envelopes into piecewise linear ones

Let P a multidimensional parameter.
You have 

phis := {phin = Fn(G(xi), P) , n=1..7 }

and you want to solve the system 

{Fn(G(xi), P) = 0 , n=1..7 }

wrt to P.

To get P you use the command

unknowns := indets(rhs~(phis), name)

which indeed returns all the names P contains, but also the name (xi) of the independent variable G depends upon.
So the error you get:
Error, (in solve) cannot solve expressions with diff(G(xi), xi) for xi

To get rid of it write

unknowns := indets(rhs~(phis), name) minus {xi};   # this is the "true" P

Now you can compute COEFFS, which is a sequence of 16 solutions:

COEFFS := solve(rhs~(phis), unknowns)

whattype(COEFFS);
                            exprseq

 numelems([COEFFS]);
                               16

Some of them depend on G(xi), which might not (?) be suitable.
If you want to get rid of them execute

GfreeCOEFFS := remove(has, [COEFFS], xi):
numelems(%);
                               9

Remark:

phis contains 7 relations while the parameter vector P has dimension 16. Which mean that 9 parameters are likely to get arbitrary values.

Maybe a better way would be to solve the system  { Fn(G(xi), Q) = 0 n=1..7 } with Q being a subvector parameter of P with size  7.
Ideally you should chose the 7 parameters which are the most relevant to the use you have in mind.

and ifI understand corrrectly your problem, here is a solution (which is likely not optimal in terms of computation time nor memory use) .
It is fast for N=8 but I didn't checked it for much larger values of N.

Round_Robin_mmcdara.mw

Maple Worksheet - Error

Failed to load the worksheet /maplenet/convert/round_robin_mmcdara.mw .



 


key: use this rewritting rule

isolate(m+1/(diff(G(xi), xi))=Phi, diff(G(xi), xi));
                       d              1   
                      ---- G(xi) = -------
                       dxi         Phi - m

and collect wrt Phi :

restart

with(PDEtools):

with(LinearAlgebra):

with(SolveTools):

undeclare(prime)

`There is no more prime differentiation variable; all derivatives will be displayed as indexed functions`

(1)

PDEtools:-declare(Omega(x, t)); 1; PDEtools:-declare(U(xi)); 1; PDEtools:-declare(u(x, y, z, t)); 1; PDEtools:-declare(Q(xi))

Omega(x, t)*`will now be displayed as`*Omega

 

U(xi)*`will now be displayed as`*U

 

u(x, y, z, t)*`will now be displayed as`*u

 

Q(xi)*`will now be displayed as`*Q

(2)

tr := {t = tau, x = (-ZETA*c[3]-tau*c[4]-`&Upsilon;`*c[2]+xi)/c[1], y = `&Upsilon;`, z = ZETA, u(x, y, z, t) = U(xi)}:

pde1 := diff(u(x, y, z, t), `$`(x, 3), z)-4*(diff(u(x, y, z, t), x, t))+4*(diff(u(x, y, z, t), x))*(diff(u(x, y, z, t), x, z))+2*(diff(u(x, y, z, t), `$`(x, 2)))*(diff(u(x, y, z, t), z))+3*(diff(u(x, y, z, t), `$`(y, 2))) = 0:

NULL

L1 := PDEtools:-dchange(tr, pde1, [xi, `&Upsilon;`, ZETA, tau, U]):

map(int, L1, xi):

ode := %:

F := sum(a[i]*(m+1/(diff(G(xi), xi)))^i, i = -1 .. 1):

D1 := diff(F, xi):

S := diff(G(xi), `$`(xi, 2)) = -(2*m*mu+lambda)*(diff(G(xi), xi))-mu:

E1 := subs(S, D1):

D2 := diff(E1, xi):

E2 := subs(S, D2):

D3 := diff(E2, xi):

E3 := subs(S, D3):

``

K := U(xi) = F:

K1 := diff(U(xi), xi) = E1:

K2 := diff(U(xi), `$`(xi, 2)) = E2:

K3 := diff(U(xi), `$`(xi, 3)) = E3:

``

L := eval(ode, {K, K1, K2, K3}):

# rewritting rule

RR := isolate(m+1/(diff(G(xi), xi))=Phi, diff(G(xi), xi));

diff(G(xi), xi) = 1/(Phi-m)

(3)

# Apply RR and collect wrt Phi

subs(RR, L):
normal(%):
PhiN := collect(numer(lhs(%)), Phi):
PhiD := denom(lhs(%%));

Phi^4

(4)



with(LargeExpressions):

LLE := collect(PhiN, Phi, Veil[phi] ):
LLE / PhiD = 0;

(3*Phi^8*phi[1]+6*Phi^7*phi[2]+Phi^6*phi[3]+Phi^5*phi[4]-Phi^4*phi[5]-Phi^3*phi[6]+Phi^2*phi[7]-6*Phi*phi[8]+3*phi[9])/Phi^4 = 0

(5)

# phi[i] coefficients

print~( [ seq( phi[i] = simplify(Unveil[phi](phi[i]), size), i=1..LastUsed[phi] ) ] ):

phi[1] = mu^2*a[1]*c[1]^2*c[3]*(2*mu*c[1]+a[1])

 

phi[2] = lambda*mu*a[1]*c[1]^2*c[3]*(2*mu*c[1]+a[1])

 

phi[3] = -8*a[1]*(mu*c[3]*(m^2*mu^2+m*mu*lambda-(7/8)*lambda^2)*c[1]^3+(3/4)*((m^2*a[1]+a[-1])*mu^2+m*mu*lambda*a[1]-(1/2)*lambda^2*a[1])*c[3]*c[1]^2+(1/2)*mu*c[1]*c[4]-(3/8)*mu*c[2]^2)

 

phi[4] = -8*lambda*a[1]*(c[3]*(m^2*mu^2+m*mu*lambda-(1/8)*lambda^2)*c[1]^3+(3/4)*(m*lambda*a[1]+mu*(m^2*a[1]+2*a[-1]))*c[3]*c[1]^2+(1/2)*c[1]*c[4]-(3/8)*c[2]^2)

 

phi[5] = -2*((m^2*a[1]+a[-1])*mu+m*lambda*a[1])*c[3]*(m^2*mu^2+m*mu*lambda-(1/2)*lambda^2)*c[1]^3-3*((m^4*a[1]^2+4*m^2*a[-1]*a[1]+a[-1]^2)*mu^2+2*m*lambda*a[1]*(m^2*a[1]+2*a[-1])*mu+lambda^2*a[1]*(m^2*a[1]-2*a[-1]))*c[3]*c[1]^2-4*c[4]*((m^2*a[1]+a[-1])*mu+m*lambda*a[1])*c[1]+3*((m^2*a[1]+a[-1])*mu+m*lambda*a[1])*c[2]^2

 

phi[6] = -8*lambda*(c[3]*(m^2*mu^2+m*mu*lambda-(1/8)*lambda^2)*c[1]^3+(3/2)*(m*lambda*a[1]+mu*(m^2*a[1]+(1/2)*a[-1]))*c[3]*c[1]^2+(1/2)*c[1]*c[4]-(3/8)*c[2]^2)*a[-1]

 

phi[7] = -8*(mu^2*c[1]^2*c[3]*(mu*c[1]+(3/4)*a[1])*m^4+2*lambda*(mu*c[1]+(3/4)*a[1])*mu*c[3]*c[1]^2*m^3+((1/8)*mu*c[3]*c[1]^3*lambda^2+(3/4)*c[3]*(lambda^2*a[1]+mu^2*a[-1])*c[1]^2+(1/2)*mu*c[1]*c[4]-(3/8)*mu*c[2]^2)*m^2+(3/4)*lambda*(-(7/6)*c[1]^3*c[3]*lambda^2+mu*a[-1]*c[1]^2*c[3]+(2/3)*c[1]*c[4]-(1/2)*c[2]^2)*m-(3/8)*lambda^2*a[-1]*c[1]^2*c[3])*a[-1]

 

phi[8] = lambda*m*c[1]^2*(2*m^2*mu*c[1]+2*lambda*m*c[1]+a[-1])*c[3]*(m*mu+lambda)*a[-1]

 

phi[9] = m^2*c[1]^2*(2*m^2*mu*c[1]+2*lambda*m*c[1]+a[-1])*c[3]*(m*mu+lambda)^2*a[-1]

(6)
 

 

Download factoring_mmcdara.mw


Nevertheless here is a real example based on the Grid package and a specific strategy (read carefully the text).
 

restart

with(Grid):


Run N_sim simulations on N_noeud nodes (can be larger than Numnodes() )

Here I want to solve an ode system to determine the temporal evolution of X(t ; P) for different
values of a parameter vector P.

Those values are gathered  in a matrix named Ver_plan_exp. of dimensions N_sim by N_P where
N_P is the size of P.

Ver_plan_exp is considered as made of N_blocs blocks of equal sizes T_blocs by N_P.

Those N_blocs blocs are run independently on N_noeud nodes: in case N_blocs is larger than N_noeud
the first N_noeud blocs are simulated and once all have ended their job another bunch of N_noeud blocks
is sent to them dor simulation. The process keeps going on until all the N_blocs blocks are simulated.

This very simple strategy (Grid:-Wait command) is acceptable as the simulation times for each bloc are roughly
the same (so I use here some kind of synchronous strategy).
When it's not the case it's better to use an asynchronous strategy: as soon as one of the active node ens its task its is
charged with a new vlock without waiting for the other to send and ending signal. This strategy is suitable when the
different blocs lead to significantly different execution times.
Finally, you can notice there is no master node here as all the N_noeud nodes do exactly the same task.
I could have use a special node, let's say node 0, to monitor the tasks of the remaining  N_noeud-1 
slave nodes. This master node then have the task to distribute the simulation and to gather ther results these latters
deliver.
At this point it's worth saying that, in my case, the procedure run on each node (SIMULER_MP) generates a huge
matrix made of  T_bloc rows and hundreds of columns. If each node has to return such a matrix to a possible
master node in order this latter aggregate them, this will have a cost in terms of communication time and memory
used. This is why I prefered not to use a master node here.

Of course the choices between  synchronous vs  asynchronous strategy and  all-slaves vs one-master strategy are
problem dependent.
But they also depend on the OS you use and of what the term node means: are the nodes physical or logical.
The strategy I present here is the simplest one, and it proved to be the most efficient for my problem on my machine
(a 24 nodes PC (12 physical) with 64 Gb memory under Windows 10... for information I got better performances using
Windows XP which didn't interfere with the Grid commands, see below).
At last, the value of N_bloc may impact the efficiency: too small block sizes mean more communications and thus
penalize the computational time, but this can limit the memory consumption. So here again a "good" choice will depend on
your machine and the OS you use.


The key procedure here is SIMULER_MP whose aim is to sole the ode system for all the parameter (row) vectors
P defined by the submatrix plan_bloc = Ver_plan_exp[bloc].

This procedure is declared this way
SIMULER_MP := proc(
                    num_bloc,
                    entree,
                    sortie,
                    Drag_sol,
                    tps_decollement,
                    Ver_piecewise_va,
                    mur,
                    tps_max,
                    ICI
              )

As I said above the solutions computed by this procedure are gathered in a big matrix named RESULT.
I found that the most efficient solution was, after the construction of this matrix, to save it in binary format
before ending procedure SIMULER_MP :

save RESULT, cat(ICI, "/tps_", num_bloc, ".m");
end proc:


In the code below you see that how the nine arguments of SIMULER_MP are passed in the Grid:-Run command.

Once all the simulations are done it may be interesting to kill the processes associated to all the nodes but node 0 (which
is the default number associated to your worksheet) to freeze the memory.
The way to do that depends on the OS you use.

It remains to read all the m files and to gather their content, if necessary,in a single m file.


Last advices:

(1)  it may be interesting to use a number of nodes lower than the number Grid:-NumNodes returns if you
       want to assume some light tasks aside (mailing, text edititong..., things like that),
(2)   keep an aye on the monitor panel to see the nodes are correctly loaded.

        (when the code below was ran under Window XP the task monitor displayed 20 nodes with a 100% charge,
        when ranunder Windows 10 it this was no longer the case because Windows 10 [and presumablyt higher versions]
        use its own managing process to load the nodes. The result was that, on the same machine, the computational time
        was 20-25% higher with Windows 10 than with Windows XP).


Good luck.

Grid:-NumNodes();  # returns the number of nodes (starts from 0 by default)

N_noeud   := 20;
N_blocs   := 20;
N_sim     := 10^6
T_blocs   := N_sim / N_blocs;

Grid:-Setup(numnodes=N_noeud):
Grid:-Set  ('SIMULER_MP'):

printf("%s   départ\n", StringTools:-FormatTime("%H:%M:%S"));

for m from 1 to N_blocs/N_noeud do
  for noeud from 0 to N_noeud-1 do
    num_bloc  := (m-1)*N_noeud+noeud;
    bloc      := 1 + num_bloc*T_blocs..(num_bloc+1)*T_blocs;
    plan_bloc := Ver_plan_exp[bloc]:

    #-------------------------------------------------
    Grid:-Run(
      noeud,                  # target node
      SIMULER_MP,             # procedure to run
      [                        
        num_bloc,             #
        plan_bloc,            #
        [1],                  # list of arguments
        eval(Drag_sol),       #
        tps_decollement,      #
        [Ver_piecewise_va],   #
        mur,                  #
        tps_max               #
        ICI                   #
      ]                       
    ):
    #-------------------------------------------------
  end do;

  Grid:-Wait(seq(0..N_noeud-1));

  printf("%s   Fin groupe %2d\n", StringTools:-FormatTime("%H:%M:%S"), m);
end do;

printf("%s   Fin\n", StringTools:-FormatTime("%H:%M:%S"));


 

Download Example.mw


The piece of code

	
W__points := plottools:-getdata(P)[1, -1]:
t_grid := convert(W__points[..,1], list):
x_grid := [seq(-2..2, 4/N)]:
> 	
T, X := map(mul, [selectremove(has, [op(expand(solnum))], t)])[]:
ST := unapply(eval(T, W(t)=w), w)~(W__points[.., 2]):
SX := evalf(unapply(X, x)~(x_grid)):
STX := Matrix(N$2, (it, ix) -> ST[it]*SX[ix])

I sent you days ago was written to handle T3 expressions of the form F(x)*G(W(t)), which is no longer the case here.

Here is an update for your current T3 expression (in your code you gave w two different meanings: one was a parameter, the other a surrogate name for W(t), which is quite confusing ; even if I no longer use this surrogate in the code below, I thought it would be better to avoid confusion in any future  expressions like eval(..., W(t)=w) and then arbitrarily renamed w as psi).

 

restart;

currentdir(kernelopts(':-homedir')):

randomize():

local gamma:

T3 := (B[1]*(tanh(2*n^2*(delta^2-psi)*k*t/((k*n-1)*(k*n+1))+x)-1))^(1/(2*n))*exp(I*(-k*x+psi*t+delta*W(t)-delta^2*t));

(B[1]*(tanh(2*n^2*(delta^2-psi)*k*t/((k*n-1)*(k*n+1))+x)-1))^((1/2)/n)*exp(I*(-k*x+psi*t+delta*W(t)-delta^2*t))

(1)

params := {B[1]=1, n=2, delta=2, psi=1, k=3 }:

insert numerical values

solnum :=subs(params, T3):

N := 100:
use Finance in:
  Wiener := WienerProcess():
  P := PathPlot(Wiener(t), t = 0..10, timesteps = N, replications = 1):
end use:

W__points := plottools:-getdata(P)[1, -1];
t_grid := convert(W__points[..,1], list):
x_grid := [seq(-2..2, 4/N)]:

`#msub(mi("W"),mi("points"))` := Vector(4, {(1) = ` 101 x 2 `*Matrix, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(2)

T3_param := eval(T3, params):

STX := Matrix(
         (N+1)$2
         , (it, ix) ->
           evalf(
             eval(
               eval( T3_param, W(t)=W__points[it, 2])
               , {t=t_grid[it], x=x_grid[ix]}
             )
           )
         );

STX := Vector(4, {(1) = ` 101 x 101 `*Matrix, (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(3)

plots:-matrixplot(Re~(STX));

 

# Export STX as you use to do

 


 

Download S5_mmcdara.mw

The simplest way, IMO, to get this table  is to use the option output=Array in dsolve/numeric:

when    := [seq(0..50, 1)]:
sol     := dsolve(`union`(sys, ic), numeric, output=Array(when)):
sol[1];  # to verify the order of the outputs
results := round~(sol[2][1]):

printf("%-10s %-15s %-15s %-15s\n", "Day", "Infected", "Recovered", "Susceptible");
printf("---------------------------------------------\n");

fmt := "%-10d %-15d %-15d %-15d\n":
map(i -> printf(fmt, entries(results[i+1], nolist)), when):
y := substring(x, 1..1)

To get the value of y:

x := asdf:
a := 3:
y := substring(x, 1..1);
                               a
eval(y)
                               3

This doesn't answer your question, just to say that geom3d provides an elegant way (IMO) to determine if a point is on a line.

restart
with(geom3d):
line(L, [3+2*alpha, 1+6*alpha, 4-5*alpha], alpha):

point(A, 9, 19, -11):
IsOnObject(A, L)
                              true
point(B, 9, 1, -11):
IsOnObject(B, L)
                             false


Plus an animation to illustrate the demonstration
Similar_Triangles_Animation.mw

1 2 3 4 5 6 7 Last Page 1 of 59