1

I want to plot the following quadratic form:

f(x) = 1/2 x^T * A * x -b^T *x 

where A is a 2x2 matrix. x1-axis: [-6,4] x2-axis: [-4,6]

I did the following:

x = arange(-6,4,0.1)
y = arange(-4,6,0.1)

So both x and y conatain 100 points. Now I want to evaluate the quadratic form at all those pairs of points, i.e. I get 100*100 = 10000 points.

Done by the following code:

res= []
for a in x:
    for b in y:
        val = f(array([a,b]))
        res.append(val)

Now I want to make a kind of surface plot. Can anyone help me figure out how to do this? I tried:

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
surf = ax.plot_surface(x, y, res)

I think the following method should be help but I really do not know how exactly:

griddata- Interpolates from a nonuniformly spaced grid to some other grid.

any ideas?

Alexander
  • 11
  • 4
  • Can you show us the error message you're getting when you try to execute this code? Your problem could be a number of things, and it would help to narrow it down. – Nat Knight Sep 30 '15 at 20:31
  • Edited initial post, there was a minor error. I get the following error: `ValueError: shape mismatch: two or more arrays have incompatible dimensions on axis 1.` Well I understand I think because x,y are both arrays which conatain 100 points each whereas res contains 10000 points. Is there an easy way to solve this? – Alexander Oct 01 '15 at 08:22
  • It sounds like you want the [`mplot3d`](http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html) module of matplotlib. Are you using that? You might find [this question](http://stackoverflow.com/questions/9170838/surface-plots-in-matplotlib) helpful as well. – Nat Knight Oct 01 '15 at 18:26

0 Answers0