Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE WRITE IN C AND ONLY USE STDIO.H, NOT MATH.H Write a function, cos(x), using the taylor expansion and use it in a program to

PLEASE WRITE IN C AND ONLY USE STDIO.H, NOT MATH.H

Write a function, cos(x), using the taylor expansion and use it in a program to find the cosine of values read until EOF.

Here you will be writing a function:

 double cos(float); 

to compute the cos of an angle (given in radians) using the Taylor series shown. Your function should find the value of the cos for ANY angle (preferred) or at least angles up to 2 PI (Hint: if you can do the later, the former should be easy) to a precision of 4 decimal places (within 0.00005). You should put the function cos() in the file called trig.c. You can use the function pos_power() in your exponent.c from Lab 6 and Hw 4, and you should write functions for factorial() and close_enough() in the file called util.c. This last function is given two doubles and returns true if they are within 0.00005 of each other. You can put any other functions you may want in util.c as well. You will need to provide your own .h files for each of these .c files. You should also write a simple test driver to exercise your function in the file driver1.c. You should update the makefile to compile and link driver1.c, trig.c, util.c and exponent.c when you type

 make trig 

and create the executable called trig.

NOT SURE IF THE BELOW CODES ARE FULLY RELEVENT

Exponent.h

float pos_power(float base, int exponent);

double cos(float)

Exponent.c

#include"exponent.h"

{ int x, y; i=1; ans=1;

while(i<=y) { ans=ans*x; i=i+1; }

return 0;

}

UTIL.C

float factorial(int i) { int i; for(i = 2; i <= 2 * acc; i += 2) i* = 1; return i; }

float close_enough(float a, float b) { float c=a-b; if(c < 0) { c = c * (-1); } if(c <= 0.00005) return 1; else return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

5. What information would the team members need?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago