[go: up one dir, main page]

Items tagged with matrix

Feed App Center

I am trying to check if the inputs are a pair of row or column matrices. How should I do that? I have tried type but no success.


 

restart

 

TestDim:=proc(p1::{Matrix(1,3),Matrix(3,1)},p2::{Matrix(1,3),Matrix(3,1)},prnt::boolean:=Prntmsg)
description "Midpoints, Bilines";
uses RationalTrigonometry;
local x1, y1, z1, x2, y2, z2,m1,m2,xpsn , ypsn,zpsn ;

if [Dimension(p1)]=[1,3] and [Dimension(p2)]=[1,3] then  
      m1:= Vector[row](3);
      m2:= Vector[row](3);
      print([1,3]);
  elif [Dimension(p1)]=[3,1]and [Dimension(p2)]=[3,1] then
      m1:= Vector[column](3);
      m2:= Vector[column](3);
       print([3,1]);
 else
      ERROR(p1,p2, `must both be row or column matrices`);
end if;
end proc

proc (p1::{Matrix(1, 3), Matrix(3, 1)}, p2::{Matrix(1, 3), Matrix(3, 1)}, prnt::boolean := Prntmsg) local x1, y1, z1, x2, y2, z2, m1, m2, xpsn, ypsn, zpsn; description "Midpoints, Bilines"; if [Dimension(p1)] = [1, 3] and [Dimension(p2)] = [1, 3] then m1 := Vector[row](3); m2 := Vector[row](3); print([1, 3]) elif [Dimension(p1)] = [3, 1] and [Dimension(p2)] = [3, 1] then m1 := Vector[column](3); m2 := Vector[column](3); print([3, 1]) end if end proc

(1)

f:=<<a|b|c>>;
g:=<<d|e|h>>

f := Matrix(1, 3, {(1, 1) = a, (1, 2) = b, (1, 3) = c})

 

g := Matrix(1, 3, {(1, 1) = d, (1, 2) = e, (1, 3) = h})

(2)

TestDim(f,g)

 


 

Download 2024-08-18_Test_Matrix_Dimension.mw

Why doesn't evalf work on the data structures below?
 

M1 := Matrix([[m__1, m__2]])

Matrix(%id = 36893488151929448556)

(1)

M := [M1, M1]

[Matrix(%id = 36893488151929448556), Matrix(%id = 36893488151929448556)]

(2)

m__1 := 1; m__2 := 2

M

[Matrix(%id = 36893488151929448556), Matrix(%id = 36893488151929448556)]

(3)

evalf(M)

[Matrix(%id = 36893488151929440844), Matrix(%id = 36893488151929440964)]

(4)

evalf(M[1])

Matrix(%id = 36893488151929437108)

(5)

evalf(op(M))

Matrix(%id = 36893488151929432292), Matrix(%id = 36893488151929432412)

(6)

evalf(op(M[1]))

1., 2., {(1., 1.) = m__1, (1., 2.) = m__2}, datatype = anything, storage = rectangular, order = Fortran_order, shape = []

(7)

NULL


 

Download evalf.mw

Suppose we have the following simple Matrix

T := <1,2;3,4>;

How do we replace an entry with another expression?

I know that for a list L := [1,2,3] we can do, for example subsop(2=500,L) to replace the entry at index 2.

This creates a new list since lists are immutable.

As far as I can tell, a Matrix is mutable.

However, I wish to change an entry in a Matrix without mutating it.

My actual use case is the following.

I use LinearAlgebra:-Eigenvectors to obtain a Matrix of eigenvectors. Some of the entries are huge expressions with many variables. I would like to sub in placeholders where these huge expressions are so I can visualize the Matrix better, but without modifying the original Matrix.

Dear all, in the example below I create a matrix(3x2) and each element contains a vector. How can I avoid the double brackets of the matrix elements or eliminate the double brackets?

Thanks for help

Hi

 I know that (G, A)=Basis(F,output=extended) computes reduced Groebner basis for polynomial ideal F, while  A is a list of lists.  If A is converted to a matrix, we get G=FA. Is there a command to compute matrix B such that F=GB?

Thank you. 

For the legend in the image below I would have expected a black image and not a white

 

 

Hi everyone ...

How can I define the below Matrix with for command: (A[n] is n*n and n=1...i)

Tnx...

Should not  print("my matrix is ",A) at least print "my matrix is " even if A is not correctly filled/setup?

Notice that nothing shows on screen when using print (but lprint does)

Is this expected? If it makes any difference, I am using worksheet and this is my display options

21836

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

A:=Matrix(1,0);

print("My matrix is =",A);

lprint("My matrix is =",A);

"My matrix is =", Matrix(1,0,{},datatype = anything,storage = rectangular,order
= Fortran_order,shape = [])

 

 

Download why_print_empty_june_7_2024.mw

Let M a matrix of zeros and ones for instance.

N := 10^5:  # This is the order of magnitude I have to consider (10^4 may be enough if L is "small")
L := 5:     # L is between 3 and 8 in practice (see context at the end of this post)
M := LinearAlgebra:-RandomMatrix(N, L, generator=0..1):

Let C a set of colums of M and |C| the number of elements of C.
Let P a list of length |C| of  zeros and ones.

I want to count al the rows in M such that 

`and`( seq( M[n, C[k]] = P[k], k = 1.. |C| ) )

For instance

pattern := n -> `if`(evalb(`and`(seq(S[n, C[k]]=P[k], k=1..3))), 1, 0):
t0 := time():
add(pattern(n), n=1..N);
time()-t0
                             12351
                             0.431  # seconds

This code appears to be quite slow when one consider that I have to run it for all the possible choices of C and P (the contect is detailed below).

Do you have any some ideas to improve the efficiency (in terms of computational time) of this counting operation?
Thanks in advance





The context:
Let A = {1, 2, .., L} and P(A) the power set of A.
I set Q(A) = P(A) \ ( { } union A}.
Let C and C'  two disjoint subsets of Q(A).
Example

# With L=3

Q(A) = { {1},  {2},  {3},  {1, 2},  {1, 3},  {2, 3} }

# if A chose C = 
C = {2}

# Then C' is member of 
C' in { {1}, {3}, {1, 3}

For any couple (C, C')  I want to do this

  1. Let |C| (|C'|) cardinal of C (resp C').
     
  2. Let us consider that members of C (resp C') "point to" the corresponding columns of M.
    for instance C = {2, 3} refers to columns 2 and 3 of M.
    As C and C' are ordered iI will write them indistinctely as lists (for instance C = [2, 3] in example above) when necessary.
     
  3. To a given |C| (|C'|) one may associate 2|C| (resp 2|C'|) sequences of 0 and 1.
    For instance,  to C = {2, 3} are associated sequences [0, 0], [0, 1], [1, 0], [1, 1].
    Let s(C) (s(C')) the list, or set, of 0-1 sequences associated to C (resp C')..
     
  4. For any couple (C, C') and any of the 2|C|+|C'| combinations (p, p') where p belongs to s(C) and p' belongs to s(C') I want to count the number of occurrences defined by: 
    seq( M[n, C[k]] = p[k], k=1..|C|) and seq( M[n, C'[k]] = p'[k], k=1..|C'|) 

    For instance, if C={2} and C={1, 3} I want to count the number M rows M such that 

    p = [0], p'=[1, 0]
    M[n, 2]=0 and M[n, 1]=1 and M[n, 3]=0;
    
    p = [1], p'=[1, 1] 
    M[n, 2]=1 and M[n, 1]=1 and M[n, 3]=1
    
    ... and so on

The computational time may ne quite large because of the number of possible couples (C, C') when L is large ( there exists  Stirling2(L+1, 3) such couples: already 90 couples for L=5  ... and 28501 for L=10).

I learnt that MapleFlow (MF) was a product similar (and better) than MathCad (MC). I have a old copy of MC, v.11 (with Maple symbolic engine) and I compared it with MF from my engineering dep. 

Can one kindly explain why Sum of a simple Matrix does not work, if the index is placed as exponent? Here what I did:

SI_MODEL.mw
I have tried the following code to simulate the following SI Model. But when I run it, it gives me several mistakes and most importantly does not calculate the Jacobian Matrix and the eigenvalues. 

Any help would be deeply appreciated


Many of the most interesting dynamics in nature have to do with interactions between organisms. These interactions are often subtle, indirect, and difficult to detect. Interactions in which one organism consumes all or part of another. This includes predator-prey, herbivore-plant, and parasite-host interactions. These linkages are the prime movers of energy through food chains. They are an important factor in the ecology of populations, determining the mortality of prey and the birth of new predators.

Mathematical models and logic suggest that a coupled system of predator and prey should cycle: predators increase when prey is abundant, prey are driven to low numbers by predation, the predators decline, and the prey recover, ad infinitum. One such model that simulates predator-prey interactions is the Lotka - Volterra Model.

 


We will discuss a behavior of 2 D - subsystems: SI - model.


SI Model (without predator)

 

We will study a mathematical model that appears in eco - eco-epidemiology.


The SI model describes the interactions between S-prey with density x and I-prey with density y under the assumption z≡0


Break the population into compartments.

• 

Prey (S)

• 

Infected prey (I)


SI Equations :

(D(x))(t) = r*x(t)-b*x(t)^2-c*x(t)*y(t)-beta*x(t)*y[t]/(a+x(t))

(D(y))(t) = -mu*y(t)+beta*x(t)*y(t)/(a+x(t))

– 

 r stands for the intrinsic growth rate of S-prey.

– 

b defines the intra-class competition in S-prey.

– 

c characterizes the inter-class competition between S-prey and I-prey.

– 

μ stands for the mortality of the I-prey

– 

β considered as the bifurcation parameter.

• 

Note: The dynamics of the system depend on parameter β

 

Modeling with Differential Equations

 

• 

We will fix the parameters in the study to have the following values r = 1, b = 1, c = 1/100, μ = 4/10, a=1/2.75.

• 

The initial values will be x(0)=0.2, y(0)=0.05


As mentioned above the dynamics of the system depend on parameter β. So we will consider two cases when β=0.75 and β=1


We will solve the system for the above values of parameters and initial conditions and for a time interval [0,200] , then we will create its plots

 

Case 1

  restart

beta := .75; r := 1; b := 1; c := 1/100; mu := 4*(1/10); a := 1/2.75; f := r*x(t)-b*x(t)^2-c*x(t)*y(t)-(3/4)*x(t)*y(t)/(a+x(t)); g := -mu*y(t)+(3/4)*x(t)*y(t)/(a+x(t)); deq1 := diff(x(t), t) = f; deq2 := diff(y(t), t) = g; equilibrio := solve({f = 0, g = 0}, {x(t), y(t)}); jacobian := simplify(Matrix(2, 2, [[diff(f, x(t)), diff(f, y(t))], [diff(g, x(t)), diff(g, y(t))]])); A := simplify(eval(jacobian, equilibrio[1])); B := simplify(eval(jacobian, equilibrio[2])); Q := simplify(eval(jacobian, equilibrio[3])); eigen1 := Eigenvalues(A); eigen2 := Eigenvalues(B); eigen3 := Eigenvalues(Q); soln := dsolve({deq1, deq2, x(0) = .2, y(0) = 0.5e-1}, numeric, output = listprocedure); plots:-display(plots:-odeplot(soln, [t, x(t)], 0 .. 200, color = blue, legend = ["x(t)"]), plots:-odeplot(soln, [t, y(t)], 0 .. 200, color = red, legend = ["y(t)"]), labels = ["t", "Population"], title = "Population Dynamics")

 

NULL

 

 

Case 2

restart``

beta := 1; r := 1; b := 1; c := 1/100; Mu := 4*(1/10); a := 1/2.75; f := r*x(t)-b*x(t)^2-c*x(t)*y(t)-x(t)*y(t)/(a+x(t)); g := -Mu*y(t)+x(t)*y(t)/(a+x(t)); deq1 := diff(x(t), t) = f; deq2 := diff(y(t), t) = g; equilibrio := solve({f = 0, g = 0}, {x(t), y(t)}); jacobian := Matrix(2, 2, [[diff(f, x(t)), diff(f, y(t))], [diff(g, x(t)), diff(g, y(t))]], simplify); J_at_equilibrio := [eval(jacobian, equilibrio)]; eigen1 := Eigenvalues(A); eigen2 := Eigenvalues(B); eigen3 := Eigenvalues(Q); soln := dsolve({deq1, deq2, x(0) = .2, y(0) = 0.5e-1}, numeric); plots:-display(plots:-odeplot(soln, [t, x(t)], 0 .. 200, color = blue, legend = ["x(t)"]), plots:-odeplot(soln, [t, y(t)], 0 .. 200, color = red, legend = ["y(t)"]), labels = ["t", "Population"], title = "Population Dynamics with Beta = 1")

 

NULL


 

Download SI_MODEL.mw

 

 

Dear all,

the BlockCopy command is a miracle for me that I don't understand. Is there an easier command or an easy to understand documentation?

Thanks

Dear all, I'm new with maple. How can I extend an existing matrix?

XX := Matrix(2, 4, [[1, 1, 1, 1], [2, 2, 2, 2]])

extend(XX,1,0,0) # doesn't work

Thanks for help

How to show that any Pythagorean triplet can be obtained from <3,4,5> ? Thank you.
Can we simplify this program?

#Génération Géométrique et Algébrique des triplets Pythagoriciens
restart;
with(geometry);
with(LinearAlgebra);
_EnvHorizomtalName = 'x';
_EnvVerticalName = 'y';

with(plottools);
P := point([0, 0], color = black, symbol = cross, symbolsize = 25);
Oo := point([1/2, 1/2], color = black, symbol = cross, symbolsize = 25);
A := point([1, 1/2], color = black, symbol = cross, symbolsize = 25);
with(plots);
c1 := circle([1/2, 1/2], 1/2, color = blue);
NULL;
PA := line([0, 0], [1, 1/2], color = red);
eqC := (x - 1/2)^2 + (y - 1/2)^2 = 1/4;
eqPA := y = 1/2*x;
sol := solve({eqC, eqPA}, {x, y});

t1 := textplot([0, 0, 'typeset'("P"), font = [Times, Bold, 14]], 'align' = 'above');
t2 := textplot([1, 1/2, 'typeset'("A"), font = [Times, Bold, 14]], 'align' = 'right');
t3 := textplot([1/5, 1/10, 'typeset'("A'"), font = [Times, Bold, 14]], 'align' = 'above');
A1 := point([1 - 1/5, 1/10], color = black, symbol = cross, symbolsize = 25);
diff(A, x) := point([1/5, 1/10], color = black, symbol = cross, symbolsize = 25);
t4 := textplot([1 - 1/5, 1/10, 'typeset'("A1"), font = [Times, Bold, 14]], 'align' = 'right');
A2 := point([1 - 1/5, 1 - 1/10], color = black, symbol = cross, symbolsize = 25);
t5 := textplot([1 - 1/5, 1 - 1/10, 'typeset'("A2"), font = [Times, Bold, 14]], 'align' = 'right');
A3 := point([1/5, 1 - 1/10], color = black, symbol = cross, symbolsize = 25);
t6 := textplot([1/5, 1 - 1/10, 'typeset'("A3"), font = [Times, Bold, 14]], 'align' = 'right');

poly := Matrix([[1/5, 1/10], [1 - 1/5, 1/10], [1 - 1/5, 1 - 1/10], [1/5, 1 - 1/10]], datatype = float);
pol := polygonplot(poly, color = blue, transparency = 0.95);

display(c1, P, Oo, A, PA, seq(A || i, i = 1 .. 3), seq(t || i, i = 1 .. 6), pol, scaling = constrained, axes = none, size = [600, 600]);

R1 := Transpose(<<1, -2, 2> | <2, -1, 2> | <2, -2, 3>>);
R2 := Transpose(<<1, 2, 2> | <2, 1, 2> | <2, 2, 3>>);
R3 := Transpose(<<-1, 2, 2> | <-2, 1, 2> | <-2, 2, 3>>);
V := <3, 4, 5>;
MatrixVectorMultiply(R1, V);
MatrixVectorMultiply(R2, V);
MatrixVectorMultiply(R3, V);
t1 := <2225, 3648, 4273>;
t2 := MatrixVectorMultiply(1/R1, t1);
t3 := MatrixVectorMultiply(1/R3, t2);
t4 := MatrixVectorMultiply(1/R2, t3);
t5 := MatrixVectorMultiply(1/R1, t4);
t6 := MatrixVectorMultiply(1/R3, t5);
MatrixVectorMultiply(MatrixMatrixMultiply(MatrixMatrixMultiply(MatrixMatrixMultiply(MatrixMatrixMultiply(R1, R3), R2), R1), R3), V);
% - t1;
NULL;
 

ras5_v1.mw 

How can I  change eq13 to eq14 without using op command manually?

Thank you for your help in advance,

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