Ask Your Question
0

Unbrackable blanck

asked 2020-10-26 18:21:08 +0200

Cyrille gravatar image

updated 2020-10-26 18:21:51 +0200

In the following code I am obliged to insert / to inside my fonction to obtain the desired result.

nl=3 #nombre de contraintes
nc=4  #nombre de variables
ring=QQ
A=matrix(ring,nl,nc,[1.5,2,4,3,4,1,2,1,2,3,1,2])
b=vector(ring,[550,700,200])
c=vector(ring,[4,6,3,1]) 

### code ####
def simplex_tableau_sf(A, b, c,cond=1) :
    # A matrice des contraintes
    # b vecteur des contraintes
    # c vecteur des paramètres de l'objectif
    # 1 (défaut) tableau

    I=identity_matrix(A.nrows())
    L=block_matrix([[A,I]],subdivide=False)
    L=L.augment(b)
    n=A.nrows()
    m=A.ncols()
    z1=vector([0 for i in range(n+1)])
    c=flatten(-c)
    z1=flatten(z1)
    zc=vector(c+z1)
    L=matrix(L.rows()+[zc])
    rows = list(L)
    hr=['$x_{}$'.format(i) for i in range(0,nc+nl)]
    hr=list('')+list(hr)+list('b')
    hc=list('xc2')+['$x_{}$'.format(i) for i in range(4,7)]
    t = table(rows, header_row=hr, header_column=hc, frame=True)
    if cond == 1 :
        return t
    elif cond != 1 :
        return L

So is there a blank which can be used as a string

edit retag flag offensive close merge delete

Comments

Can you clarify? It is not clear what you are asking. In Python, ' ' is a blank string. In LaTeX, '~' is a blank.

John Palmieri gravatar imageJohn Palmieri ( 2020-10-26 22:47:33 +0200 )edit

John look the difference when I use hr=list('/')+list(hr)+list('b'), hr=list(' ')+list(hr)+list('b') and hr=list('/')+list(hr)+list('b'). The only case where I obtain a correct result is the first and I want to have a blanc space not a \.

Cyrille gravatar imageCyrille ( 2020-10-28 19:17:27 +0200 )edit

What happens if you use ' ' rather than ''?

John Palmieri gravatar imageJohn Palmieri ( 2020-10-28 19:56:39 +0200 )edit

Sorry John, I send the wrong code. I have changed it in the question. I hope now it is correct. My problem is only with the /. Now with ' ', it works. I don't know why earlier, I have a wrong result.

Cyrille gravatar imageCyrille ( 2020-11-01 12:21:42 +0200 )edit

Quick comment: you can replace elif cond != 1 : with else:

John Palmieri gravatar imageJohn Palmieri ( 2020-11-02 19:57:16 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2020-10-28 20:03:25 +0200

Here is a screenshot of what your code produces for me (using Sage 9.2):

image description

If I change '' to '/', it adds an extra column to the header row, so that the column "b" has nothing beneath it. Is that really what you want?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-10-26 18:21:08 +0200

Seen: 147 times

Last updated: Oct 28 '20