# Graphic of function y=sin(1/x)

• Good evening!
I need to display the graph somehow:
y = sin(1/x); 0.9 <= x <= 2.8; Δx = 0.2;
Does anyone know what formula to apply to this function via code? :)

• Hi
That it the formula.
it says
y = sin(1/x);
and x goes from 0.9 to 2.8 in step 0.2

for for each value in x, you can get the y
and then paint it your self with QPainter or use QChart.

So im not sure what you are asking ?

• I just don't really understand the condition, other than y=sin(1/x). And if I draw using QPainter, I don't even know how to implement it using this formula. After all, you need to not just draw from the line, but somehow enter accurate data.

My problem is that I don't know how to implement this formula via QPainter :\

• @Troyer

Hi
Well it says to do like this

``````    double y = 0;
double deltax = 0.2;
for (double x = 0.9; x <= 2.8; x += deltax ) {
y =  sin(1.0 / x);
paint.drawPoint( 100 + int(x),100 + int(y));
}
``````

However, since its very small values, drawing them directly is not very visible since
its super tiny.

So might be better to use QtCharts as it can zoom.

• You could use LineSeries with ChartView natively with your function. You can use a for loop for plotting each point depending on how you would like to Plot it, finally set the graph. First of all read the docs for functions if something similar is available, else reply back to this thread