I need help with Taylor Series
Part A:
Scan the angle in degrees x_deg. Express this angle in
radians by using x=PI*x_deg/180, and calculate Y=cos^2(x)
by using the math.h library of functions (pow() and cos()
functions). Compare the so calculated value of Y=cos^2(x)
with the approximate value y obtained by using n_term
terms of the Taylor series
cos^2(x)=0.5*(1 +Sum[(1)^n (2*x)^(2n)/(2n)!]),
where n goes from 0 to n_term. Print the relative error
100*(Yy)/Y.
Scan an integer value of n_term. Evaluate (2n)! by an embedded
forloop statement. Use two do/while statements to continue
the calculations for different n_term and different x_deg. For
example, use flag=1 to continue calculations for different n_term
within the inner do/while loop, and flag=0 to exit that loop.
Use Flag=1 to continue calculations for different x_deg
within the outer do/while loop, and Flag=0 to exit that loop
and go to Part B. (Recall that 0!=1).
This is my program:
#include <stdio.h>
#include <math.h>
#define PI 3.141592654
main()
{
int n_terms, n=0;
double angle_deg, angle_rad, csa, csa2, taylor, sum;
printf("\n\nPar t A:\nCalculation of True and Approximate Values of cos^2(x)\n\n");
printf("Enter x_deg: \n");
scanf("%lf", &angle_deg);
angle_rad = angle_deg * (PI/180.);
csa = cos(angle_rad);
csa2 = pow(csa, 2.);
printf("True value of cos^2(x) = %f\n\n", csa2);
printf("n_term approximation of cos^2(x)\n\n");
printf("Enter number of terms:\n");
scanf("%d", &n_terms);
printf("\n%d term approximation\n ", n_terms);
}
so far everything shows up correctly. I'm just stuck on how to use the for loop to calculate the taylor series.
Oct 25 '06
12 39196
can nyou try it using the taylor series?
Why would there be no math.h?
using this format:
in getting the sin of a value x:
sin(x) = x^1/1!  x^3/3! + x^5/5!....
Laharl 849
Recognized Expert Contributor
You do know that is a Taylor series, right? Whether or not <math.h> is there has no effect on that...and <math.h> is a standard library. It should always be there, unless you're on a microcontroller or something. Note that if you're using gcc, you need to compile with the lm flag to actually have the math library included, as well as the #include.
Thread necromancy aside, you'd just need to write your own exponent function to replace pow(), as that's the only math.h function involved in the computations.
Sign in to post your reply or Sign up for a free account.
Similar topics 
by: Dick Moores 
last post by:
I need to figure out how to compute pi to base 12, to as many digits as
possible. I found this reference,
<http://mathworld.wolfram.com/Base.html>, but I really don't understand
it well enough. Could someone show me how to do what I need?
Thanks,
Dick Moores
rdm@rcblue.com

by: oz 
last post by:
Hi,
Where can i find code examples of connecting with MQ from VB.net(not using
msmq bridge)
BR
Oz

Outgoing mail is certified Virus Free.

by: chb1980 
last post by:
this is a question..about Taylor series...
1) Find the Taylor series approximation of order 2 (n=2) for the funtion f(x,y)=sin(xy) about (x。,y。)=(π/4,π/4) using this approximation , compute the function value at x=0.77 and y=0.80
could you handle it ..?

by: chb1980 
last post by:
this is a question..about Taylor series...
1) Find the Taylor series approximation of order 2 (n=2) for the funtion f(x,y)=sin(xy) about (x。,y。)=(π/4,π/4) using this approximation , compute the function value at x=0.77 and y=0.80
could you handle it ..?

by: mia023 
last post by:
Hi i just want to ask if i want to write a java program that compute sin x and cos x using Taylor series. I don't know the logic about how to write this program and how to get Taylor series through programming
 
by: ninita 
last post by:
Hi everybody!
Does anyone know how to program in java to put the tayor series??
I really need help!

by: pancholijaymin 
last post by:
can i get the solution immediately for the cpp program onthe taylor series which has prototype as follows:
double getTaylorSeries(double xValue, int maxTerm):
Where, the parameter xValue represents the value of x and maxTerm is the maximum limit of the terms

by: arperidot 
last post by:
hey guys, the question asks to
Scan the angle in degrees using x=PI*x_deg/180 and calculate Y=sin^2(x).
Calculate sin^2(x) approximately by using n terms (n>0) the Taylor series
sin(x)=Sum (k goes from 0 to n1)
Scan an integer value of n. Evaluate (2k+1)! by an embedded forloo statement. Use two do/while statements to continue the calculations for different n and different x_deg.
Calculate the error between the Y value and the...

by: Ben Stone 
last post by:
I am trying to write C code for sin(x) using the first 5 terms of the taylor series. I am new to programming and am not allowed to use loops. I don't have much yet, but what I have so far is:
/* solution to Taylor Series approximation of sin(x) */
#include <stdio.h>
#define PI 3.1416f
int main ()
{
float x_deg;

by: marktang 
last post by:
ONU (Optical Network Unit) is one of the key components for providing highspeed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...

by: Hystou 
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
 
by: tracyyun 
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, ZWave, WiFi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...

by: agi2029 
last post by:
Let's talk about the concept of autonomous AI software engineers and nocode agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...

by: isladogs 
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...

by: conductexam 
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...

by: TSSRALBI 
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LANtoLAN VPNs.
The last exercise I practiced was to create a LANtoLAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

by: muto222 
last post by:
How can i add a mobile payment intergratation into php mysql website.
 
by: bsmnconsultancy 
last post by:
In today's digital era, a welldesigned website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
 