Ask Your Question
1

code works line by line in console but not loaded as a sage file

asked 2020-07-14 01:10:59 +0200

joboujp gravatar image

updated 2020-07-14 22:56:17 +0200

slelievre gravatar image

I tried the tutorial to solve an equation system. I enter the code commands line by line in Sage and it works, but when put it all together in a sage file it does not show the results. It seems it's just the last line of the code that shows the results that is not working.

Here is the code:

var('A1, A2, N1, N2, q')
eq1 = A1 == N1/(N2*q + N1)^2
eq2 = A2 == q^2*N2/(N2*q + N1)^2
eqns = [eq1, eq2, A1 == 0.160, A2 == 0.015, N2 == 10]
solns = solve (eqns, A1, A2, q, N1, N2, solution_dict=True)
[[s[N1].n(30), s[q].n(30)] for s in solns]
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-07-14 22:55:36 +0200

slelievre gravatar image

In interactive use, the last computed result is always displayed.

In non-interactive use, it is not. To get it displayed, use print.

var('A1, A2, N1, N2, q')
eq1 = A1 == N1/(N2*q + N1)^2
eq2 = A2 == q^2*N2/(N2*q + N1)^2
eqns = [eq1, eq2, A1 == 0.160, A2 == 0.015, N2 == 10]
solns = solve (eqns, A1, A2, q, N1, N2, solution_dict=True)
print([[s[N1].n(30), s[q].n(30)] for s in solns])
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

Stats

Asked: 2020-07-14 01:10:59 +0200

Seen: 141 times

Last updated: Jul 14 '20