Instead, you should consider how to do range reduction.įor example, can you use the identity exp(x+y) = exp(x)*exp(y) Look more carefully at the terms in the series for exp(x).Īnyway, I assume this is why you have been given this homework assignment, to learn that series like this don't converge very well for large values. The y = y*k line does not do what you need. In fact the following was even more efficient: s = 1 Īs John points out in a comment, you have an error inside the loop. ![]() Not sure if it's completely correct but it returns some good approximations.Īfter further analysis (and unfortunately submitting the assignment), I realised increasing the number of iterations, and thus increasing terms, further improves efficiency. So I somewhat understand that the problem surrounds large numbers when there is 16 (or more) orders of magnitude between terms, precision is lost, but the solution eludes me. Explain the behaviour carefully and give a simple fix which produces a better result. Your colleague believes that there is a silly bug in the program, and asks for your assistance. Which mathematical function does this code approximate? (I say the exponential function.) Does it work when x = 1? (Yes.) Unfortunately, using this when x = -100 produces the answer s = 8.7364e+31. ![]() Does anyone know how to make the following Matlab code approximate the exponential function more accurately when dealing with large and negative real numbers?įor example when x = 1, the code works well, when x = -100, it returns an answer of 8.7364e+31 when it should be closer to 3.7201e-44.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |