0

I have a code which perfectly draws a sine wave graph

y = mgl_create_data_size(100,1,0);
mgl_data_modify(y,"0.4*y+0.1+sin(6*pi*x)",0);
gr = mgl_create_graph(WINDOW_WIDTH, WINDOW_HEIGHT);
mgl_plot(gr,y,". ","");
mgl_box(gr);

Now that the variable y is a MathGL data type HMDT
How I will get numeric values from it

I see there is function which mgl_data_get_value(y,i,j,0);

but it only accepts long data type and it always returns NaN

Dickens A S
  • 3,824
  • 2
  • 22
  • 45

1 Answers1

0

I found the answer that, I am trying to assume j as incremental value.

But, base on trial and error based, when I set j as 0 I am getting all the 100 graph values which applied based on the MathGL formula 0.4*y+0.1+sin(6*pi*x).

So the assumption of the function mgl_create_data_size is
If the data is set using 100,1,0 which is nx,ny,nz
nx = 100 - Total number of X axis values
ny = 1 - is only one Y value for each X value
nz = 0 - is assumed as 0, there is no z axis
the function which can get each graph value is

mgl_data_get_value(y,i,0,0)

Example of 10 values for the same formula

var y1 = mgl_create_data_size(10,1,0)
mgl_data_modify(y1,"0.4*y+0.1+sin(6*pi*x)",0)
for(i in 0..10-1) {
   println(mgl_data_get_value(y1,i,0,0))
}

The output is

0.1
0.9660254037844387
-0.7660254037844384
0.09999999999999976
0.9660254037844391
-0.7660254037844387
0.09999999999999952
0.9660254037844401
-0.7660254037844377
0.09999999999999927

The graph in Excel for the above values is enter image description here

This is very help full to use MathGL in applied mathematics in data generation as one of the light weight libraries

Dickens A S
  • 3,824
  • 2
  • 22
  • 45