/* File sinr_r.c Calculate function sinr(x,y) = sin(sqrt(x*x+y*y))/sqrt(x*x+y*y) for x from -10 to 10 with step size 10, and for y from -10 to 10 with step size 10 */ #include #include #include int main() { double x,x0,xf,xstep, y,y0,yf,ystep, function, r, xsq,ysq,sum; int i,j,nx,ny; printf("%10c %10c %10s %10s %10s %10s\n",'x','y',"xsqared","ysquared","x^2+y^2","sinr(x,y)"); printf("--------------------------------\n"); /*Initial, final, step size, number of points*/ x0 = -10.0; xf = 10.0; xstep = 10.0; nx = (xf-x0)/xstep + 1; y0=-10.0; yf=10.0; ystep=10.0; ny = (yf-y0)/ystep + 1; for(i=x0;i<=xf;i+=xstep) { x = i; for(j=y0;j<=yf;j+=ystep) { y = j; xsq = x*x; ysq = y*y; sum = xsq + ysq; printf("%10.4f %10.4f %10.4f %10.4f %10.4f ",x,y,xsq,ysq,sum); /*If the sum has a value smaller than elipson, sinr(x,y) = 1 */ if(fabs(sum) < FLT_EPSILON) { function = 1; } else { function = sin(sum)/sum; } printf("%10.4f\n",function); } } return 0; }