polynomial-math

Can someone explain the behavior of the functions mkpp and ppval?

此生再无相见时 提交于 2019-12-12 17:08:39
问题 If I do the following in MATLAB: ppval(mkpp(1:2, [1 0 0 0]),1.5) ans = 0.12500 This should construct a polynomial f(x) = x^3 and evaluate it at x = 1.5 . So why does it give me the result 1.5^3 = .125 ? Now, if I change the domain defined in the first argument to mkpp , I get this: > ppval(mkpp([1 1.5 2], [[1 0 0 0]; [1 0 0 0]]), 1.5) ans = 0 So without changing the function, I change the answer. Awesome. Can anyone explain what's going on here? How does changing the first argument to mkpp

Efficient calculation of polynomial coefficients from its roots

我们两清 提交于 2019-12-12 10:55:36
问题 I have the roots of a monic polynomial, i.e. p(x) = (x-x_1)*...*(x-x_n) and I need the coefficients a_n, ..., a_0 from p(x) = x^n + a_{n-1}x^{n-1} + ... + a_0. Does anybody know a computationally efficient way of doing this? If anybody knows a C/C++ implementation, this would actually be the best. (I already had a look at GSL but it did not provide a function.) Of course, I know how to to it mathematically. I know, that the coefficient a_i is the sum of all products of the subsets with n-i

sympy: Collect symbols for matrix coefficients?

﹥>﹥吖頭↗ 提交于 2019-12-12 09:05:12
问题 I am trying to factor an expression, and separate coefficients to matrix form, such that: Closely related to Factor sympy expression to matrix coefficients?, where Wild symbols are used with match(form) to determine coefficients for its matrix form. However, I am unable to get the match(form) method to work for the following. Why does match(form) method fail? What are clean alternatives to accomplish this? #Linear Interpolation function: V(x) v_1, theta_1, v_2, theta_2, x, L = symbols("v_1,

Sort Polynomial based on Symbol and Exponent

丶灬走出姿态 提交于 2019-12-12 06:46:27
问题 I'm writing writing polynomial arithmetic in lisp, and currently working on addition. I need help sorting a polynomial by the exponent and symbol. My polynomials are represented as follows: ((3 ((1 x)(1 y))) (1 ((3 y)))) ; == 3xy + 1y^3 The function I need guidance with is given a term like ((5 ((3 x))) (3 ((3 y))) (4 ((2 z)))) ((6 ((3 x))) (1 ((3 y))) (9 ((2 z))))) I would want: ((4 ((2 Z))) (9 ((2 Z))) (5 ((3 X))) (6 ((3 X))) (3 ((3 Y))) (1 ((3 Y)))) returned, so that all So all z^2 and z^2

Ruby Regex To Capture Any Numerical Characters In a String

放肆的年华 提交于 2019-12-12 03:32:12
问题 So, I've done a lot of research, and looked at tons of regex documentation, guides, and regex generators, but nothing I have found can tell me how to do this (not even the links in the StackOverflow popup box that appeared when I typed "regex" into the "Title" field for this question). So basically, I'm writing a math program (in Ruby) to solve a very specific type of math problem. There will be two inputs that take strings (via gets.chomp), and one string will take the form of 2x^3+4x^2+5x

A code for finding one root of fifth degree polynomial

陌路散爱 提交于 2019-12-12 03:14:02
问题 I'm trying to write a code that asks from the user to give 5 coefficients for a 5th-degree polynomial, and it also asks to give a range (two values) that the programs checks if there is a solution in it or not (I'm asked to find only one), and the solution must be an integer, while the coefficients can be floats. I'm thinking of writing a code that runs over every integer in the range and substitute it in a description of a polynomial than I define, and check if its equal to zero, but I got

Running time complexity of Horner's method

丶灬走出姿态 提交于 2019-12-11 17:17:32
问题 Here is a pseudocode for Horner's method for computing the value of a polynomial at x (where a[i] denotes the coefficient of x^i) : y=a[0] for i = n to 1 y = a[i] + x*y Many articles on the internet state that the running time of Horner's method is proportional to n . But since the number of terms in y is proportional to (n-i) (when we have already completed i iterations), shouldn't the total time taken be (n-1)+(n-2)....1 which is proportional to n^2 ? Or do we always consider that any

Generate random polynomials with MATLAB

情到浓时终转凉″ 提交于 2019-12-11 12:07:44
问题 I want to generate random binary polynomials with parameters (n,m) . n is the number of polynomials to be generated and m is the number of elements of each polynomials. At the same time I need it's polynomial to be unique. And I also need to exclude the result with all elements equal to zero. For example for n=3 and m=3 I am looking for something like [1 0 1] [1 0 0] [1 1 1] . Is there any command in mat lab which I can use to have the above results?? I would also like to avoid the for loop

Souriau method for Characteristic Polynomial

放肆的年华 提交于 2019-12-11 11:23:41
问题 Does anyone know the Souriau method for finding the characteristic polynomial of any n × n matrix? I found out the first coefficient, is obvious, but how can I find out the other coefficients? After I need to inverse the matrix but I know how. #include <iostream> #include <fstream> using namespace std; double trace(double a[5][5],int n){ int i; double trace=0; for(i=0;i<n;i++) trace+=a[i][i]; return trace; } double prod(double a[5][5],double b[5][5],int n) { double c[5][5]; int i,j,k; cout <<

Isolating coefficients from polynomial fit in r

我是研究僧i 提交于 2019-12-11 09:08:39
问题 I have fitted a simple 2nd order polynomial to time series data in the following form: polyfit <- lm(y ~ poly(x,2)) I wish to extract the respective coefficients (A, B and C) from the fitted polynomial of the form y = Ax^2 + Bx + C. I naturally thought the answer would be found in polyfit$coefficients within the polyfit object but these coefficients are not correct. I have tried some very simple data sets and compared with excel and whilst the poly curve fits are identical in R and excel, the