I've no idea how to solve this Q with C.

help me~~ plz~~!!

Attachments
5
Contributors
15
Replies
16
Views
6 Years
Discussion Span
Last Post by Stefano Mtangoo

What specifically are you having trouble with?
You just need to create a function or two that will perform the maths calculations exactly as stated. Define a value for PI or use the math header file and then assign the stated value for x and plug it into your functions.

Maybe you should try writing out your (attempted) solution as pseudo code first so that you can get your head around what you need to do. Then translating from pseudo code to C should be relatively simple.

I am new to C++ and am still learning it. In college decades ago, I took Cal III and learned about the Maclaurin and Taylor series expansions. A couple of years ago I dusted off my old textbook and wrote a Javascript program that computes normal probability values using the Taylor series expansion. I understand how to write your program.

The issue is whether YOU understand the problem to be solved. Before I could write the normal probability program, I had to compute the normal probabilities BY HAND! I wrote pseudocode to organize the different parts of the program. (One part, for example, is the factorial function.) I drew a flowchart to track the movements of values, specifically, the function calls and function returns. (For example, the call of the factorial function and the return of the factorial function value.)

If you are able to answer the problem's questions by hand, then you can (eventually) write a C++ program to solve the problem. People on this site will be able to help you with the code. If you can't, then no one can help you. Others will be able to solve the problem for you, but you yourself still won't be able to solve it. You would need to go back to calculus and improve your understanding of infinite series.

``````const int Pi = 3.14; //Constant
{
}
float x = 0.3f*Pi;              // x = 0.3PI
int n = 10;                     // n = 10
float valOrig =  cos(toDeg(x)); //To degree from radian
float valComp = 0.0f;           //Compute this value
float Es = (0.5 x pow(10,2-n);  //Es
float Ea = 0.0f;                //Compute Ea later
int i=0;                        //Loop counter
do
{
valComp += pow(-1,i)*pow(x,2i)/fact(2i); //Maclaurin Series
Ea = (valOrig - valComp)/valOrig;        //Compute Ea
i++;
}while(Ea < Es);``````

That should be all.

Don't give the answer away... it's not fair to the OP
``````const int Pi = 3.14; //Constant
{
}
float x = 0.3f*Pi;              // x = 0.3PI
int n = 10;                     // n = 10
float valOrig =  cos(toDeg(x)); //To degree from radian
float valComp = 0.0f;           //Compute this value
float Es = (0.5 x pow(10,2-n);  //Es
float Ea = 0.0f;                //Compute Ea later
int i=0;                        //Loop counter
do
{
valComp += pow(-1,i)*pow(x,2i)/fact(2i); //Maclaurin Series
Ea = (valOrig - valComp)/valOrig;        //Compute Ea
i++;
}while(Ea < Es);``````

That should be all.

Are you here to make people cheat their professors? :@
OP haven't shown any effort than dumping the question.So he/she will copy and pasted and cheat the prof. That is NOT what Daniweb is all about.

Edited by Stefano Mtangoo: n/a

Oh! I thought Nathaniel10's post to be OP's post & hence I gave my step-by-step procedure thinking he didn't understand the question. Guess I screwed up this time past the 30min mark.
Will be careful next time. :(

Oh! I thought Nathaniel10's post to be OP's post & hence I gave my step-by-step procedure thinking he didn't understand the question. Guess I screwed up this time past the 30min mark.
Will be careful next time. :(

Its ok!
there are people who would like to earn degree through another body, that is lying cheating....full garbage :)

lol~! I can handle these Q by my hand, but the plob is I've no idea about c++. lol..

I tried to make any code for this by myself and find some code...

I even can't understand any code of c++

Could you recommend some book to study of programming for me?

If you can manage to scribble up an algorithm, starting with the general term of the Maclaurin/Taylor Series then only the code semantics need to be placed in order.

Could you recommend some book to study of programming for me?

Now you are talking :)
Check there is recent thread on that and I shamelessly recommended, among others Soulie's tutorial at cplusplus.com

Wow, Thanx mate~!

But, I'm still dizzying.

I'm try to solve it and make code step by step,

I've got a question.

How can I make Maclaurin Series ??

1) add = pow(-1,i) * pow(x, 2*i) / factorial(2*i);

2) valComp += pow(-1,i) * pow(x,2i)/factorial(2i);

when I do 'Debugging' both way, there are several errors which make me crazy...

BTW have you skimmed though tutorial to get idea of what C++ looks like?
Without doing that will be like someone walking in streets of Dar es salaam going to Manzese and he have never been in Dar es salaam and don't have any map.
He will not get anywhere and will keep "making errors"

This c++ problem goes over my head..... lol

Edited by cdh1944: n/a

This c++ problem goes over my head..... lol

love shortcuts? They are long cuts under disguise :icon_lol:

Thankx!! evstevemd & nbaztec !!

Finally I made up my fantastic code!!!

I've got another Q, I'll try it with big smile!! :>

Thankx!! evstevemd & nbaztec !!

Finally I made up my fantastic code!!!