Ask Your Question
0

Batch processing

asked 2022-09-18 12:25:50 +0100

Andr gravatar image

updated 2022-09-18 13:02:21 +0100

So far I have used sagemath one command at once. I need solve hundreds of equations, with coefficients from text file and print output to text file. Sage enables environment like Python?

I want create input.sage file with equations like

eqA1 =1.754223-1.189676*x-0.908315*y+0.686618*x^2-0.725235*x*y-1.352818*y^2 == 0
eqB1 =1.463137-0.511047*x-0.297305*y-1.671951*x^2-0.100824*x*y-1.717723*y^2 == 0
eqA2 =
eqB2 =
.........

in main command/file do load('input.sage') and in loop solve its, and save results to text file

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-09-24 09:43:52 +0100

Andr gravatar image

Goal: create testusite with correct solutions: I have samples.sage:

eq0a =1.754223168770020-1.189676139503717*x-0.908314931206405*y+0.686617674306035*x^2-0.725234915502369*x*y-1.352818138897419*y^2 == 0
eq0b =1.463137484435483-0.511046565137804*x-0.297304930165410*y-1.671951361931860*x^2-0.100823741406202*x*y-1.717722679488361*y^2 == 0
eq1a =1.333662021786013-0.908314931206405*x+0.686617674306035*y-0.725234915502369*x^2-1.352818138897419*x*y-0.511046565137804*y^2 == 0
eq1b =0.418361927859167-0.297304930165410*x-1.671951361931860*y-0.100823741406202*x^2-1.717722679488361*x*y+1.363417739048600*y^2 == 0
eq2a =0.054290627837304-0.626953722909093*x-1.718449720181525*y+1.862912494689226*x^2-1.980401362292469*x*y+0.330725008621812*y^2 == 0
eq2b =-0.894123614194686-0.083563295193017*x+0.953402206301689*y+1.470303879119456*x^2+0.665378382429481*x*y+0.444558157585561*y^2 == 0

After

solutions = solve([eq0a, eq0b], x, y)
sage: print(solutions)

I have

[
[x == 0.03137993762993763, y == 0.8340287436254057],
[x == 0.4135661133371494, y == 0.657632522917497],
[x == (-0.01014352680353612 + 0.8819542016100413*I), y == (-1.361968819165564 + 0.06838174575693547*I)],
[x == (-0.01014352680353612 - 0.8819542016100413*I), y == (-1.361968819165564 - 0.06838174575693547*I)]
]

Now I want output.txt with coefficients and roots:

0
1.754223168770020
-1.189676139503717
-0.908314931206405
0.686617674306035
-0.725234915502369
-1.352818138897419
real roots=2
0.03137993762993763
0.8340287436254057
0.4135661133371494
0.657632522917497
1
......

How do it ? how output numbers to text file with Sage?

edit flag offensive delete link more

Comments

Since you insist on a text file, the Python documentation should answer your question.

A remark : you are not solvng equations, but equation systems ; account for this in your solution.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-09-25 08:38:56 +0100 )edit
0

answered 2022-09-20 08:31:40 +0100

Emmanuel Charpentier gravatar image

This tutorial and the relevant part of the manual should give you some inspiration...

The very short version :

  • load reads and executes the content of the file(s) passed as an argument.

  • attach does the same thing, but also "watches" them and re-loads them when they are modified externally.

Perusing the (many) Sage tutorials may enlighten you further...

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: 2022-09-18 12:25:50 +0100

Seen: 214 times

Last updated: Sep 24 '22