0% found this document useful (0 votes)
33 views5 pages

Un Modelo de Colas

This document describes a queue model using Python code. It defines variables for the number of states and transition probabilities, initializes a matrix, and populates it with transition probabilities between states. It then calculates and displays the eigenvalues and eigenvectors of the transition matrix.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views5 pages

Un Modelo de Colas

This document describes a queue model using Python code. It defines variables for the number of states and transition probabilities, initializes a matrix, and populates it with transition probabilities between states. It then calculates and displays the eigenvalues and eigenvectors of the transition matrix.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Un modelo de colas

May 24, 2022

1 Un modelo de colas

[1]: from math import*


import numpy as np
import sympy as sp
from sympy import Matrix
from numpy import matrix
from sympy import poly
from sympy.abc import x,y

[2]: m = 10
p = 0.45
q = 0.4

[3]: M = np.zeros((m+1, m+1)); M

[3]: array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])

[4]: M[0,0] = 1-p


M[1,0] = p
M[m-1,m] = q
M[m,m] = 1-q

[5]: M

[5]: array([[0.55, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0.45, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],

1
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.4 ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.6 ]])

[6]: for i in range(1,m):


M[i-1,i] = (1-p)*q
M[i,i] = (1-p)*(1-q)+p*q
M[i+1,i] = p*(1-q)

[7]: M

[7]: array([[0.55, 0.22, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],


[0.45, 0.51, 0.22, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0.27, 0.51, 0.22, 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0.27, 0.51, 0.22, 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0.27, 0.51, 0.22, 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0.27, 0.51, 0.22, 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0.27, 0.51, 0.22, 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0.27, 0.51, 0.22, 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.27, 0.51, 0.22, 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.27, 0.51, 0.4 ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.27, 0.6 ]])

[8]: N = Matrix(M)

[9]: N
[9]:  0.55 0.22 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0


 0.45 0.51 0.22 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 


 0.0 0.27 0.51 0.22 0.0 0.0 0.0 0.0 0.0 0.0 0.0 


 0.0 0.0 0.27 0.51 0.22 0.0 0.0 0.0 0.0 0.0 0.0 

0.0 0.0 0.0 0.27 0.51 0.22 0.0 0.0 0.0 0.0 0.0
 
 
0.0 0.0 0.0 0.0 0.27 0.51 0.22 0.0 0.0 0.0 0.0
 
 
0.0 0.0 0.0 0.0 0.0 0.27 0.51 0.22 0.0 0.0 0.0
 
 
0.0 0.0 0.0 0.0 0.0 0.0 0.27 0.51 0.22 0.0 0.0
 
 

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.27 0.51 0.22 0.0

 
 
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.27 0.51 0.4 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.27 0.6

[10]: np.linalg.eig(M)

2
[10]: (array([0.03204345, 0.06772821, 0.1390245 , 0.24516746, 0.37766687,
0.52413948, 0.670461 , 0.8023994 , 1. , 0.97428661,
0.90708302]),
array([[-0.070205 , -0.11193243, -0.1349204 , -0.14573681, 0.15106326,
0.153918 , 0.15555664, -0.15653309, -0.05177876, -0.15741577,
0.1571097 ],
[ 0.16528699, 0.24537205, 0.25204081, 0.20193328, -0.11833275,
-0.01809273, 0.08517504, -0.17958571, -0.1059111 , -0.30358819,
0.25500549],
[-0.21548978, -0.26432521, -0.14903085, 0.05501391, -0.2378142 ,
-0.3159951 , -0.25606008, 0.08149606, -0.1299818 , -0.3187038 ,
0.13890448],
[ 0.26530574, 0.23024149, -0.05801921, -0.31405209, 0.28827518,
0.0018956 , -0.29129507, 0.32871611, -0.15952312, -0.30000498,
-0.06224942],
[-0.31191989, -0.13846141, 0.28073652, 0.31053389, 0.11846127,
0.387934 , 0.1017942 , 0.33687479, -0.19577837, -0.24199213,
-0.28282907],
[ 0.35205274, -0.00421649, -0.4021872 , 0.01161174, -0.4250484 ,
0.02260623, 0.43174395, 0.04431199, -0.24027346, -0.14251074,
-0.43408764],
[-0.38203428, 0.17840643, 0.3336488 , -0.39508781, 0.11028838,
-0.47464791, 0.18997105, -0.3545427 , -0.29488106, -0.00376341,
-0.43638629],
[ 0.39791612, -0.35348035, -0.06902267, 0.46134972, 0.45531029,
-0.0582498 , -0.39130873, -0.52560141, -0.36189949, 0.16695726,
-0.25489966],
[-0.39562436, 0.49165751, -0.29308844, -0.07048505, -0.40922953,
0.5787787 , -0.51855443, -0.26345003, -0.44414937, 0.35696427,
0.07549077],
[ 0.37115409, -0.55457524, 0.57893069, -0.48135314, -0.31263252,
0.10868669, 0.10202544, 0.29490795, -0.54509241, 0.54843306,
0.44908642],
[-0.17644238, 0.28131364, -0.33908806, 0.36627234, 0.37965903,
-0.38683369, 0.390952 , 0.39340604, -0.36793738, 0.39562443,
0.39485521]]))

[11]: T=np.array([[ 0.13749776, 0.21923474, 0.25125616, 0.26279646, 0.26754052,


0.12251924, -0.26956108],
[-0.31816529, -0.42322399, -0.28559976, -0.02014612, 0.26197428,
0.25060753, -0.4720845 ],
[ 0.39713031, 0.29163269, -0.24122259, -0.53965673, -0.24308644,
0.30756379, -0.361224 ],
[-0.45626532, 0.00945001, 0.58084486, -0.03202424, -0.6037404 ,
0.37746465, -0.11891517],
[ 0.48543837, -0.37443754, -0.25858507, 0.65893839, -0.40261706,
0.46325208, 0.21344233],

3
[-0.47506485, 0.64315957, -0.46594009, 0.10859489, 0.27351051,
0.56853664, 0.55855231],
[ 0.22942902, -0.36581547, 0.41924649, -0.43850264, 0.4464186 ,
0.38376223, 0.44979011]])

[12]: S=Matrix(T); S
[12]:  0.13749776 0.21923474 0.25125616 0.26279646 0.26754052 0.12251924 −0.26956108

−0.31816529 −0.42322399 −0.28559976 −0.02014612 0.26197428 0.25060753 −0.4720845 
 
 0.39713031
 0.29163269 −0.24122259 −0.53965673 −0.24308644 0.30756379 −0.361224  
−0.45626532 0.00945001 0.58084486 −0.03202424 −0.6037404 0.37746465 −0.11891517
 
 0.48543837 −0.37443754 −0.25858507 0.65893839 −0.40261706 0.46325208 0.21344233 
 
−0.47506485 0.64315957 −0.46594009 0.10859489 0.27351051 0.56853664 0.55855231 
0.22942902 −0.36581547 0.41924649 −0.43850264 0.4464186 0.38376223 0.44979011

[13]: N**100
[13]:  0.0258821157612462 0.025423395551323 0.0243291245855139 0.0228219552248823 0.0211226968436521 0

 0.0520023999913425 0.0511181512886818 0.0490086815844942 0.0461029879436538 0.042826559914862 0

 0.0610741453954532 0.0601470183082429 0.0579349725673421 0.0548872785200201 0.0514496500141923 0

 0.0703112548039316 0.0694402442374455 0.0673616600018429 0.0644967851084575 0.0612637430194901 0
0.0798660947374334 0.0791655877915316 0.0774933778106326 0.0751873209784652 0.0725829518145979 0


0.0901596340846592 0.0897494859408904 0.0887698080810226 0.0874173096772594 0.0858875936110017 0


0.101953674807636 0.101946631712671 0.101928856868114 0.101901960857317 0.101867939520083


0.116413773000679 0.116901084581957 0.118063364665396 0.119663720766125 0.121467301149395



 0.135157030835663 0.136193399806297 0.138666599365879 0.142075373205673 0.145922223062756

 0.16027996561853 0.161869253525022 0.165662683014818 0.170892943093563 0.17679817167447
0.106899910963431 0.108045747255944 0.110780871454949 0.114552364624588 0.118811169375504

[14]: B=np.array([0.04092726, 0.1252987 , 0.29992873, 0.53313468, 0.76542285,


1. , 0.93528778])
A=Matrix(B)
A
[14]: 0.04092726
 0.1252987 
 
0.29992873
 
0.53313468
 
0.76542285
 
 1.0 
0.93528778

[15]: U=np.ones([m,m]); U

[15]: array([[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],

4
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]])

[16]: for i in range(1,m): # esta sentencia indica los valores que tomarÃą i
U[0,0] = 1 # Se define la entrada de la fila 0, columna 0 como 1
U[i,i] = U[i-1,i-1] + i+1 # Para generar cualqier entrada [i,i] se usa la␣
,→entrada [i-1,i-1] y se suma i+1

[17]: U

[17]: array([[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[ 1., 3., 1., 1., 1., 1., 1., 1., 1., 1.],
[ 1., 1., 6., 1., 1., 1., 1., 1., 1., 1.],
[ 1., 1., 1., 10., 1., 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 15., 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1., 21., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1., 1., 28., 1., 1., 1.],
[ 1., 1., 1., 1., 1., 1., 1., 36., 1., 1.],
[ 1., 1., 1., 1., 1., 1., 1., 1., 45., 1.],
[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 55.]])

[18]: V = Matrix(U); V
[18]: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0

1.0 3.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 
 
1.0 1.0 6.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 
 
1.0 1.0 1.0 10.0 1.0 1.0 1.0 1.0 1.0 1.0 
 
1.0 1.0 1.0 1.0 15.0 1.0 1.0 1.0 1.0 1.0 
 
1.0 1.0 1.0 1.0 1.0 21.0 1.0 1.0 1.0 1.0 
 
1.0 1.0 1.0 1.0 1.0 1.0 28.0 1.0 1.0 1.0 
 
1.0 1.0 1.0 1.0 1.0 1.0 1.0 36.0 1.0 1.0 
 
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 45.0 1.0 
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 55.0

[ ]: print("Ingrese un NÞmero : ")


num = int(input())
cont = 0
suma = 0
while cont <= num:
suma = suma+cont
cont = cont+1
print("La Suma es : ",suma)

Ingrese un NÞmero :

You might also like