Revision history [back]

Plot the level sets of a function

I'm trying to draw level set of a function f:R^2->R, that is the set of solutions of f(x,y)=h for a given h.

For that purpose I wrote the following

#! /usr/bin/sage -python
# -*- coding: utf8 -*-

from sage.all import *

def level_curve(f,h):
solutions_list = solve(f==h,y)
return [sol.rhs() for sol in solutions_list]

var('x,y')
f=x+y+2
for g in level_curve(f,3):
print g

print "-----"

f=x**2+y**2
for g in level_curve(f,3):
print g


This works, but I'm not satisfied principally because I got the level sets under the form of a list of functions. Moreover it will not work if the level set is vertical.

Thus I would prefer to get the solution under the form of a parametric curve.

Does Sage provides something for that ?

 2 retagged FrédéricC 4131 ●3 ●37 ●85

Plot the level sets of a function

I'm trying to draw level set of a function f:R^2->R, that is the set of solutions of f(x,y)=h for a given h.

For that purpose I wrote the following

#! /usr/bin/sage -python
# -*- coding: utf8 -*-

from sage.all import *

def level_curve(f,h):
solutions_list = solve(f==h,y)
return [sol.rhs() for sol in solutions_list]

var('x,y')
f=x+y+2
for g in level_curve(f,3):
print g

print "-----"

f=x**2+y**2
for g in level_curve(f,3):
print g


This works, but I'm not satisfied principally because I got the level sets under the form of a list of functions. Moreover it will not work if the level set is vertical.

Thus I would prefer to get the solution under the form of a parametric curve.

Does Sage provides something for that ?