plfunc

plot a two-dimensional function

parametertypeunitsdescription
func(float)float*uufunction of x to be plotted
xmin,ymin,xmax,ymaxfloatuuwindow in which the function is plotted
linetypeint--see plot
returns:void

Description

plfunc plfunc plots the function func(x) as far as it is within the window xmin, ymin, xmax, ymax. Stepsize is adjusted depending on earlier changes in the curvature. As a result, functions with sudden changes may give problems.

Examples

see program sine.c on the next page
// plotting sinusoidal curves, using various degrees of series expansion
//
// features: plotting of coloured and dashed curves
//           suppression of automatic scaling
//           crossing axes
//           drawing of text with greek letter and superior numbers

#include <simplot.h>
#include <math.h>
#define Deg2Rad (M_PI/180)

void plosin(int textshft,float red, float green, float blue,
            float (*func)(float),int def, char *text)
// plots the function y=func(x). def defines dashed line
{ plcolor(red,green,blue);
   plot(0,1.7,UP);
   plotrm(0,textshft*plget(HEIGHT),UP);
   plotrm(20,0,def);
   plformat(.5,0,text);
   plfunc(func,0,-1.5,540,1.5,def);
   plcolor(Black);
}

float sinx(float x) {
   x*=Deg2Rad;
   return sin(x);
}
float sin5(float x) {
   x*=Deg2Rad;
   return x-pow(x,3)/6+pow(x,5)/120;
}
float sin9(float x) {
   x*=Deg2Rad;
   return x-pow(x,3)/6+pow(x,5)/120-pow(x,7)/5040+pow(x,9.)/362880.;
}

void pldraw(void) {
   plaxes(0,-1.5,540,1.5,120,70,"@a@ (deg)","sin @a@"," ");
   plrect(0,-1.5,540,1.5);
   plosin(6,Red,      sinx,DOWN,
          " full expansion");
   plosin(4,Green,sin5,2222,
          " sin @a@ = @a@ - @a@3^/3! + @a@5^/5!");
   plosin(2,Blue,     sin9,1141,
          " sin @a@ = @a@ - @a@3^/3! + @a@5^/5!-@a@7^/7! + @a@9^/9!");
   plframe(5,3);
}

int main() {
   plinit(PS,"plfunc",160,150,30,80,"","");
   plset(HEIGHT,3);
   plset(PLOTMODE,GXcopy);
   plset(XMARK,30);     // forces scale marks every 30 degrees
   plset(XSKIP,3);      // forces number at axis every 90 degrees
   plset(CROSS,1);      // axes P_cross in (0,0)
   plloop();
   exit(0);
}

plfunc