Python basic math -


Now, before you explain something before I cancel the question, I am too young and try to learn dragon I am doing I do not have any resources in school to know such maths.

I am doing a practice which says:

Write a function named myPi will return an approximation of PI (3.14159 ...). Use Leibniz approximation located at:

So, they show how to calculate it like this:

I do not know that in Python How to calculate I mean, I do not even know how to calculate normally, because how can I calculate something which is infinite?

Besides, there is another question. Do I really need such advanced mathematics so that the programs can be written later? Many of my friends had gone through the 12/13 program and they had no problem. So what is advanced mathematics important? Because I suspect that my friends also knew how to calculate the area of ​​a circle while they were learning.

  1. Address your first question, " How do you calculate an infinite series ", the answer is estimated , a defined number of step (" I want to take it long Am "); Or
  2. Unless the change in each step comes down to tolerance ( "I want it to be right" ).

    To illustrate these examples (here's some relatively advanced Python - there is a generator to remove some duplicate code between leibniz_series two implementations, it only As long as the series reverses the words as long as you are asking for them):

      def leibniz_series (): "" "Leibniz series (1, -1 / 3) , 1/5, -1 / 7). "" "Number = Bottom = 1.0 While true: Yield (fraction / selector) fraction * = -1 Two N = 2 def pi_steps (step = 100): Calculates pi from the Libyan range with the defined number "" = value = leibniz_series () output = 0: value = 4 * next to _ = in the borders (stages) (Value) Output + = value return output DP pi_tolarance (tolerance = 0.0001): "PI" calculates Leibniz series with defined output tolerance. "Value" = Lebanese_series () output = 0 value = 4 * next (value) while ABS (value)> tolerance: output + = value value = 4 * next (value) return output   

    According to the second question, "Do you need to know 'Advanced' mathematics in the program? ", in fact the answer " it depends what you are doing " Do you want to write a game with the physics engine? Without speed equations it would be very difficult to do this But there are other things that you can do a bit more than the extra and subtraction necessary to deal with indexing in lists etc.

    Use this specific practice software to complete the repetitive task. About In fact, about the calculation of PI (which is also available in the form of math.pi !) Do not worry if you do not fully understand mathematics at this level; Is able to understand the work (yoga on some Leibniz series, multiply by result 4) and how can break it under the steps that display that code.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -