So you would have actually gained from not reinventing the wheel. You will probably exhaust the limits; the question is for which limit. Also I need help translating this into pseudo code. Jack Sullivan Jack Sullivan 58 6. But I agree, it’s nicest. Sign up using Facebook. I’d probably create a class for this. I don’t know why I didn’t think of it; I’ve used non-tail recursion in the past, so I’m aware that the possibility exists.
Edited 5 Years Ago by user At compile time there are typically very few values I’d need the sine or cosine of; is it really clearer to write. What do you mean by “test”? That’s often predefined too. But I’ll bet you reputation you haven’t read that implementation before writing yours So you would have actually gained from not reinventing the wheel.
He doesn’t have to use a recursive function for the factorial part, just the cos taylor series part. Otherwise, you probably need at least three additional values: Also, print the number of terms used in the series approximation.
Email Required, but never shown.
The compile-time efficiency is actually going to be better than run-time efficiency compared to “normal,” But, again, there isn’t really any work; and there’s no “efficiency” issue if you just use the value you need. It will also reduce compilation time. However, I must stress that the following code will perform terribly: The parameter n in float cos int nfloat x is the l and now just do it Not exactly sure what you mean.
In case you want to be more portable, you might do:. The OP didn’t say anything about such requirement. So you would have actually gained from not reinventing the wheel.
Taylor Series Cos – C And C++ |
Edited 5 Years Ago by ddanbe: This is in the right direction but, from the question, “n represents the number in the series the user would like to calculate till”. Anyway, if you must use recursion you could use something like the code below. Using a struct was the only way I could think of to get around that. Home Questions Tags Users Unanswered. Look at the sum, it goes up to infinity and as we cannot really afford that, we’ll just quit qfter some specified depth is reached.
I’d probably create a class for this. Please be thoughtful, detailed and courteous, and adhere to our posting rules. This is the series. I updated the answer to take that into account. Well you only need the running value for tail-recursion, I think. Don’t reinvent the wheel II Someone has already provided what looks like a more robust implementation of the same functionality – here on the site: I didn’t know about it before I was writing this review.
Anyway, the main problem here is that n represents the natural ending point for the recursion, the base case, and that you then also need some index that works itself up to n. I am new to programming and appreciate any help.
Instead you can write:. All answers so far recompute the factorial every time.
C Practical and Assignment Programs-e^x series expansion
Also I need help translating this into pseudo code. All the work is done a compile-time.
Please give any feedback related but not limited to style, functionality, etc. Maybe it’s buggy or has other problems.
The sign alternating and powers of x are easy to see. I have the code for the first part of a problem, which is to write a program that reads an angle x in radians from the keyboard.
Sign up or log in Sign up using Google. That’s often predefined too.