Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write the program in C 4. Write a function, cos(x), using the taylor series expansion below and use it in a program to find

Please write the program in C

4. Write a function, cos(x), using the taylor series expansion below 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.

This is what I have for my exponent.c and exponent.h

Exponent.c

#include"exponent.h"

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

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

return 0;

}

Exponent.h

#ifndef y #define DEBUG

float pos_power(float base, int exponent);

#endif

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

3. How effective is the team?

Answered: 1 week ago