LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python - two math requirements (https://www.linuxquestions.org/questions/programming-9/python-two-math-requirements-4175463446/)

eantoranz 05-25-2013 07:56 PM

python - two math requirements
 
Hi!

I'm working on pythogoras, a personal music research project. I'm working on adding sampling synthesis. At the moment I need to solve two problems and would like to know the simplest way to work around them on python. I know I could sit down to solve them by hand but perhaps there are already standard libraries that can take care of both things:

- Given 4 pairs (x, y) that define a function (think of 3rd degree function), what is the root (x where y = 0)? There will one and only one root in my case.

- Given 4 pairs (x, y) (again, 3rd degree function), what is the value of y for a given x?

So it all revolves around 3rd degree functions. What libraries are available out there for this?

Thanks in advance.

PTrenholme 05-25-2013 08:20 PM

Have you considered using a language designed for audio signal processing (e.g., faust, etc.), or functional evaluation (e.g., pure, etc.)?

For your specific question, look here for a generic solution.

ta0kira 05-26-2013 10:34 AM

You have the problem, so now you need a model to solve the problem before you can get into the code. You should formalize the steps of the process first, e.g.
  1. Fit a 3rd-degree polynomial to 4 points. You should be able to do this with least-squares, which can be done with matrices. You need to find a in Xa=y, where X is a matrix of each x value raised to the powers 0-3 (one row per x) and y is a vector of the corresponding y values. There are various levels of sophistication for solving this. (Note that there should be an exact solution for this.)
  2. Given a 3rd-degree polynomial, find its real roots. There is a closed-form solution for this.
The next step would be to decide if you want to hand-code something or if you want to try to offload some of the math onto a package or library.

Kevin Barry

psionl0 05-26-2013 10:49 PM

To work with matrixes in python you will need something like NumPy


All times are GMT -5. The time now is 08:35 PM.