Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numerical_approx for matrices #2857

Closed
roed314 opened this issue Apr 8, 2008 · 5 comments
Closed

numerical_approx for matrices #2857

roed314 opened this issue Apr 8, 2008 · 5 comments

Comments

@roed314
Copy link
Contributor

roed314 commented Apr 8, 2008

I'm running into problems with coercing to complexes or reals in
matrices:

 sage: d = matrix([[3, 0],[0,sqrt(2)]])
 sage: b = matrix([[1, -1], [2, 2]])
 sage: e = b * d * b.inverse(); e

 [    1/sqrt(2) + 3/2 3/4 - 1/(2*sqrt(2))]
 [        3 - sqrt(2)     1/sqrt(2) + 3/2]

and when I try to run n() on the matrix e, I get:

 sage: e.n()  # or n(e)
 [snip]
 <type 'exceptions.TypeError'>: unable to coerce to a ComplexNumber

If you take a look at the source code for n(), you'll see that the first thing that it does is to try calling numerical_approx(prec) on the object, and then tries coercing to real or complex fields. So the solution is to write a method numerical_approx(prec) in the matrix base class that tries to numerically approximate the entries and make a new matrix out of them.

Component: linear algebra

Issue created by migration from https://trac.sagemath.org/ticket/2857

@dfdeshom
Copy link

Attachment: 2857.patch.gz

@dfdeshom
Copy link

comment:1

Patch attached. The functionality was already there (in change_ring() and this wrapper around it works fairly well.

@sagetrac-mabshoff

This comment has been minimized.

@mwhansen
Copy link
Contributor

comment:3

Attachment: 2857.2.patch.gz

Looks good to me.

Apply 2857.2.patch after #1763

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Apr 15, 2008

comment:4

Merged in Sage 3.0.alpha5

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Apr 15, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants