SimpleGFX  1.0
Simple Graphics Library for C Programming Education
m-linear-equation.c File Reference

Visualizing linear equations using the slope-intercept form. More...

#include "gfx/simplegfx.h"

Functions

int main ()
 

Detailed Description

Visualizing linear equations using the slope-intercept form.

Author
Sukesh Ashok Kumar

This example demonstrates one of the most fundamental concepts in algebra: the linear equation in slope-intercept form (y = mx + c). By plotting this equation pixel by pixel, students can see how slope and y-intercept work together.

Mathematical Concepts:

  • Linear equation: y = mx + c (slope-intercept form)
  • Slope (m): rate of change, rise over run (Δy/Δx)
  • Y-intercept (c): where line crosses y-axis (when x=0)
  • Linear relationship: constant rate of change
  • For every unit increase in x, y increases by m units

In This Example:

  • m = 1 (slope of 1 means 45-degree angle, rise = run)
  • c = 50 (line crosses y-axis at y=50)
  • Equation: y = 1×x + 50, simplified to y = x + 50

Programming Concepts:

  • Translating mathematical formulas to code
  • Loop iteration over domain (x values)
  • Calculating dependent variable (y) from independent variable (x)
  • Coordinate transformation (offsetting x by 50 for visibility)

What you'll learn:

  • How slope-intercept form creates a straight line
  • Why slope determines the angle of the line
  • How y-intercept positions the line vertically
  • Visualizing algebraic equations geometrically
  • The relationship between math formulas and graphics
  • How to plot continuous mathematical functions

Experiment Ideas:

  • Change m to 2: steeper line (rises faster)
  • Change m to 0.5: gentler slope
  • Change m to -1: line going down (negative slope)
  • Change c to 100: shifts line up
  • Change c to 0: line passes through origin

Compile:

gcc m-linear-equation.c gfx/simplegfx.c -o output/m-linear-equation -lX11

Run:

./output/m-linear-equation

Function Documentation

◆ main()

int main ( )