assume(x, 'real') returns non-real values when solving

asked 2017-10-26 00:29:08 +0100

%sage %var x, y

our function

f(x,y) = x*y + 8/x + 1/y

first order partial derivatives

fx(x,y) = diff(f(x,y), x) fy(x,y) = diff(f(x,y), y)

find where both are simultaneously equal to zero.

the syntax is solve([system, of, equations, to, solve], variables, to, solve, for)

To keep from finding any complex number solutions, we tell sage to assume that x and y are real numbers

assume(x, 'real') assume(y, 'real') solutions = solve([fx(x,y) == 0, fy(x,y) == 0], x, y) solutions

returns [[x == 4, y == (1/2)], [x == -2Isqrt(3) - 2, y == -1/4Isqrt(3) - 1/4], [x == 2Isqrt(3) - 2, y == 1/4Isqrt(3) - 1/4]] Why is it giving non-real values?

edit retag flag offensive close merge delete

Comments

1

Which value is non-real?

dan_fulea gravatar imagedan_fulea ( 2017-10-27 02:04:11 +0100 )edit

Welcome to Ask Sage.

To display inline code, use backticks. To display blocks of code or error messages, separate them by a blank line from the rest of the text, and indent them with 4 spaces, or select code lines and click the "code" button (the icon with '101 010').

For instance, typing

If we define `f` by

    def f(x, y):
        return (x, y)

then `f(2, 3)` returns `(2, 3)` but `f(2)` gives:

    TypeError: f() takes exactly 2 arguments (1 given)

will produce:

If we define f by

def f(x, y):
    return (x, y)

then f(2, 3) returns (2, 3) but f(2) gives:

TypeError: f() takes exactly 2 arguments (1 given)

Can you edit your question to do that?

slelievre gravatar imageslelievre ( 2017-10-30 01:49:30 +0100 )edit

When you say "Why is it giving non-real values?", I assume you mean "Why aren't the values returned as floating-point numbers?"... Right?

slelievre gravatar imageslelievre ( 2017-10-30 01:50:58 +0100 )edit