## surface (3D) graph using gnuplot

### surface (3D) graph using gnuplot

Quote:> here is my function to be graphed:

>   F(X) = (X^t * A * X)^2           // X^t denotes the transpose of X
>                                    // ^2 denotes raise to the 2nd power

>  X is a vector, A is a symmetric square matrix.

>  For 2x2 A and X =(x, y) F(X) is a surface in 3-D.
>  The x-axis has the x component of X and the y-axis the y
>  component of X.  The z-axis has the value F(X) which is a scalar.

>  How can I graph something like that? What sort of entries the data
> file needs? I tried different things but nothing seems to work right!

If you want to plot this as a function, you'll need to write out the
equation in scalar form as F(x,y) = ...  because gnuplot doesn't have
vector arithmatic built-in.

Of course, you could always define your own 2x2 vector functions for
gnuplot ...

If you want to prepare a data file, it should be in "grid" format, which
looks like this:
x00  y00  z00
x10  y10  z10
x20  y20  z20
.    .    .
xN0  yN0  zN0
[null line -- nothing except newline and/or return]
x01  y01  z01
x11  y11  z11
x21  y21  z21
.    .    .
xN1  yN1  zN1
[null line]
x02  y02  z02
x12  y12  z12
x22  y22  z22
.    .    .
xN2  yN2  zN2
and so on.

### surface (3D) graph using gnuplot

> Hi all,
> here is my function to be graphed:
>   F(X) = (X^t * A * X)^2           // X^t denotes the transpose of X
>                                    // ^2 denotes raise to the 2nd power
>  X is a vector, A is a symmetric square matrix.
>  For 2x2 A and X =(x, y) F(X) is a surface in 3-D.
>  The x-axis has the x component of X and the y-axis the y
>  component of X.  The z-axis has the value F(X) which is a scalar.
>  How can I graph something like that? What sort of entries the data
> file needs? I tried different things but nothing seems to work right!

For this kind of plot, it's not necessary to generate a datafile.
Just do it this way:

# set the matrix components:
A11 = 1.0
A12 = 1.5
A21 = A12 # it's symmetric
A22 = 2.0

F(x,y) = (A11*x + A12*y)*x + (A21*x + A22*y)*y

plot [-3:3][-3:3] F(x,y)
pause -1 'Press a key to continue'

If you have to plot this often, with elements of 'A' generated by a
program, you might want to have that program write out a file like the
above and call 'gnuplot' from your program, or pipe the commands into
a popen()'ed 'gnuplot' if your OS supports piping.

--

Even if all the snow were burnt, ashes would remain.

### surface (3D) graph using gnuplot

># set the matrix components:
>A11 = 1.0
>A12 = 1.5
>A21 = A12 # it's symmetric
>A22 = 2.0
>F(x,y) = (A11*x + A12*y)*x + (A21*x + A22*y)*y
>plot [-3:3][-3:3] F(x,y)

^^^^^
splot?

Quote:>pause -1 'Press a key to continue'

--
Dr. Eberhard W. Lisse\         /                 Swakopmund State Hospital

Private Bag 5004       \      / +264 81 1246733 (c) 64 461005(h) 461004(f)
Swakopmund, Namibia     ;____/       Domain Coordinator for NA-DOM (el108)

[...]

Ooops. Of course, you're right.

Well, that's what you get for posting untested 'code' ;-|

--

Even if all the snow were burnt, ashes would remain.