Ask Your Question

How to make a function of 'fname' that produce a file named 'fname'

asked 2017-02-18 12:38:48 -0500

Laurent B gravatar image

Hi all,

Typing a correction on some recurrent sequences $u_{n+1}=f(u_n)$ I use sage to build a nice plot illustrating the behavior of the sequence depending on the initial data. I took a nice function from this awesome book.

def escargot(f,x,u0,n,xmin,xmax,file):
    u = u0
    P = plot(x, x, xmin, xmax, color='gray')
    for i in range(n):     
        P+= line([[u,u],[u,f(u)],[f(u),f(u)]], color ='red')
        u = f(u)
    P += f.plot(x, xmin, xmax, color='blue')'/home/myfolder/f1a.png')

So everyhting work perfectly but, since there is a lot of examples to produce, I would like to make the function to have an extra argument say filename so that now the file so that now the plot is saved in /home/myfolder/filename.png, but I have no idea how sage manipulate string. Help would be welcome !

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-18 13:21:22 -0500

mforets gravatar image

Sage manipulates strings as Python does, so in

def escargot(f,x,u0,n,xmin,xmax,filename):
    ...'/home/myfolder/' + filename)

the strings '/home/myfolder/' and that in filename will be concatenated.

(more useful operations for instance here).

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


Asked: 2017-02-18 12:38:48 -0500

Seen: 42 times

Last updated: Feb 18