Results 1 to 5 of 5

Thread: How to solve math tasks in Python

  1. #1
    Join Date
    Jun 2009
    Posts
    53

    How to solve math tasks in Python

    I have worked with Python. Located currently in its infancy (basic bracing, loops, functions, decisions)

    To take up Mathematics T1 and R1 this year (will go into a science-based education), and I thought it might be wise to kill two birds with one stone. Why not try to solve some of the tasks with Python?

    • Are math and Python a good combination?
    • What makes the example math module to Python?
    • Are there any of you who use Python for general problem solving?

  2. #2
    Join Date
    Nov 2008
    Posts
    1,185

    Re: How to solve math tasks in Python

    Math works fine with python, and really very many other languages. In some very resource-intensive algorithms that you may resolve to high accuracy of the solution will in many cases be better to use C/C++. By the way, I can recommend Mathematica and MATLAB, which you can look at, which is intended to engage in mathematics on the computer.

    Math module in python gives you more advanced math functions that are not even from the default. That as the square root, cosine, sine, etc.

    I use Python a lot for general-problem-solving. And those times when python does not extend all the way to the things that take too long when I code it in python I often make a sketch of the algorithm in Python, and test it out, to see if I have understood it fully, since it is so easy to make things in python. Later codes I use it over to such. C / C + + when I've got a good and functioning algorithm.

  3. #3
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to solve math tasks in Python

    It is a very good combination. That one type or breaking down parts of the code in the python shell (IDLE), is a great advantage. Yes you can take the quick demo.

    Code:
    >>> import math
    >>> dir(math)
    ['__doc__', '__name__', '__package__', 'ACOS', 'acosh', 'asin', 'asinh', 'Atan', 'atan2', 'atanh', 'ceil ', 'copy design', 'cos', 'cosh', 'degrees', 'e', 'ERF', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf ', 'pi', 'pow', 'radiance', 'his', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
    
    >>> # we see all the math Methods module
    > >> help(math.sqrt)
    Help Wed built-in function sqrt in module math:
    
    sqrt(...)
        sqrt(x)
        
        Return the square root of x.
    
    >>> math.sqrt(64)
    8.0
    >>> from math import *
    >>> # not a good way two import, just something easiser typing for now
    >>> sqrt(150)
    12.24744871391589
    
    > >> help(pow)
    Help Wed built-in function pow in module math:
    
    pow(...)
        pow(x, y)
        
        Return x**y (x to the power of y).
    
    >>> pow(5, 5)
    3125.0
    
    >>> x = 2
    >>> [pow(a, x) for a in range(10)]
    [0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0]
    
    >>> his(5)
    -0.9589242746631385
    >>> his(degrees(25))
    -0.1709188927014062
    
    >>> [(degrees(in) ) for a in range(10)]
    [0.0, 0.6795226183513794, 0.9970697330600953, 0.7834868911723467, 0.15254772534412783, -0.5596522230095522, -0.9737305344703966, -0.8691114676419106, -0.3015246456200019, 0.4266816061477646]
    >>>

  4. #4
    Join Date
    Jun 2009
    Posts
    53

    Re: How to solve math tasks in Python

    Should have seen through the Python for math teachers. Moreover, the ingenious help function you had in the demo code, never seen before. Okay to set the details for various functions. But now, back to Python, learn much more by staying with problems in Python than to read a lot of theory from books (but have purchased 3 Python books).

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: How to solve math tasks in Python

    Yes Python is working. I have solved quite a few tasks with Project Euler using Python, and rarely have the problem again but it is slow. Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve.

Similar Threads

  1. It's all math in StarCraft 2
    By Flavia in forum Video Games
    Replies: 5
    Last Post: 05-04-2011, 10:56 PM
  2. Windows Scheduled Tasks don't luanch if tasks not finished
    By Andy Candy in forum Windows Software
    Replies: 3
    Last Post: 21-08-2009, 11:47 AM
  3. Download Python 3.0 / Python 3000
    By Amaresh in forum Software Development
    Replies: 6
    Last Post: 24-02-2009, 09:28 AM
  4. Scheduled Tasks: Notify me of missed tasks
    By Hrishia in forum Windows XP Support
    Replies: 1
    Last Post: 02-01-2009, 02:45 PM
  5. Problem with math.h pow
    By void in forum Software Development
    Replies: 2
    Last Post: 21-11-2008, 01:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,417,483.72330 seconds with 17 queries