First time here? Check out the FAQ!

Ask Your Question
1

Layouting of sage notebook

asked 14 years ago

indiajoe gravatar image

updated 14 years ago

Hi, I want to take a printout of the notebook output. But since the eqns sage calculated are too large, it wrote the entire equation in a single line. I am not able to take a printout of my notebook because of this single line output. Is there any way, I can make sage output the results in a specified width. So that I can take printout on normal A4 Size papers? Thanking in advance. -indiajoe

Update:

The notebook I am having trouble is the one in the following published page.

http://480.sagenb.org/home/pub/60/

The notorious long eqn is the one at the end of the first cell. I am not able to make them print in multiple lines.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 14 years ago

niles gravatar image

updated 14 years ago

If you can see a reasonable way to split the equation up, you could have sage store the pieces in separate variables and print them separately . . . but the obvious example I tried

sum(i*x**i for i in range(30))

automatically prints on several different lines anyway.

For your case, if you change the definition of f to

f= A2*Term1 + B2*Term2 == (42/10)**2

and change the last part to

newf=f(k=kvalue) 
newg=g(k=kvalue) 
opf = newf.lhs().operands()
show(opf[0])
print("+")
show(opf[1]==newf.rhs())
show(newg)

you'll get something like

image description

This could maybe be improved a little, but illustrates two key things:

  • use .operands() to split an equation or symbolic expression into pieces which you can print separately

  • the additional zeroes are coming from the precision of the real numbers you're working with (53 bits by default, I think). If you use rationals instead, you'll get exact values, or you could use lower-precision real numbers.

Preview: (hide)
link

Comments

@niles: Thanks for looking into my layout problem. I have updated the question with the link to the published example. It has the long eqn which is creating problem at the end of the first cell. The eqn is printing lot of unwanted zeros also. I don't know how to remove that too. Thanks again..

indiajoe gravatar imageindiajoe ( 14 years ago )

Thanks a lot. It worked perfectly...

indiajoe gravatar imageindiajoe ( 14 years ago )
1

answered 14 years ago

DSM gravatar image

updated 14 years ago

If you're willing to accept a change in size and slight difference in appearance, you could try defining

show2 = sage.misc.latex.pretty_print

and then using

show2(newf)

which produces

example compressed equation

for me.

Preview: (hide)
link

Comments

Thanks a lot both the methods worked..

indiajoe gravatar imageindiajoe ( 14 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 14 years ago

Seen: 796 times

Last updated: Mar 03 '11