Ask Your Question

How can we plot the region bounded by f(x,y)=x^2+y^2, x varies from -y to y and y varies from 0 to 3

asked 2016-09-13 03:38:24 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I am goind to find out the double integral to integrate x^2+y^2 and x varies from - y to y and y from 0 to 3. I want to know how to plot this using sage math?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-09-15 04:02:57 -0600

Eugene gravatar image

I would also like to know true-sage approach, just in case here is a clumsy approach with loops and matplotlib:

import numpy as np

import matplotlib
import matplotlib.pyplot as plt

from matplotlib.pyplot import figure
from mpl_toolkits.mplot3d import axes3d

# Define

def f(x, y):
    if not (-y <= x <= y):
        return 0
        return x ** 2 + y ** 2

# Calculate

N = 512

y = np.linspace(0, 3, N)
x = np.linspace(-3, 3, N)

z = np.zeros((N, N))

for i, _x in enumerate(x):
    for j, _y in enumerate(y):
        z[i, j] = f(_x, _y)

# Plot

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = np.meshgrid(x, y)
ax.plot_surface(X, Y, z)

image description

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


Asked: 2016-09-13 03:38:24 -0600

Seen: 260 times

Last updated: Sep 15 '16