summaryrefslogtreecommitdiff
path: root/sinr_r.c
blob: 9128dda6c76a4fe7c6fd9526505a1ac53e512d63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*  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 <stdio.h>
#include <math.h>
#include <float.h>

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;
}