Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Graph Drawing [9/9]

This exercise should also be easy. Run the given program first.

What happens when the variable unit is initialized to some other value? Try out values 70, 140, 200, 40.

You can change the initial values of variables x0 and y0 to move the graph around the screen. Change the initial value of variable unit to zoom in or out.

Exercises:

Make the program draw a graph of mathematical function

  • x * 3

Solution

#num fval = x * 3;

Make the program draw a graph of the following mathematical functions:

  • x*2
  • x*1
  • x*0.5
  • x*0 + 3
  • x.round
  • x.int
  • sin(x)
  • 2*sin(3*x)
  • 3*sin(5*x)+1
  • sin(x*x)
  • x*sin(x*x)
  • -x*x + 5
  • 1/x

(For mathematicians only) The last one might present a problem due to division by zero. There are numerous ways to solve it. Can you find a way?

Solution for 1/x:

It is probably the easiest to move the origin by half a pixel:

#num x0 = 480.5;

This slide ends the tutorial on Graph Drawing.

Click on the 'Articles' button at the top to select another article. We also suggest taking a peak into our main 'Gallery' of programs, and taking a look into 'Overview' of our main programming tutorial for beginners. Have fun!

Loading...