summaryrefslogtreecommitdiff
path: root/sinr_r.c
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-02-06 11:26:44 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2017-02-06 11:26:44 -0500
commit97a693d996c79fb2a008b19750d8bb45512e01a2 (patch)
tree6df17bfe7de7c59f7b1083828d71a91e61fae9fa /sinr_r.c
downloadengr0016-master.tar.gz
engr0016-master.tar.bz2
engr0016-master.zip
Inital commitHEADmaster
Diffstat (limited to 'sinr_r.c')
-rw-r--r--sinr_r.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/sinr_r.c b/sinr_r.c
new file mode 100644
index 0000000..9128dda
--- /dev/null
+++ b/sinr_r.c
@@ -0,0 +1,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;
+}