Menu
  • HOME
  • TAGS

Polynomial operations in matlab

matlab,polynomials

I think you're looking for remd in this expression (http://nl.mathworks.com/help/comm/galois-fields-of-odd-characteristic.html). a = gf([1 0 0 0 1 2],n); %your example b = gf([1 1],n); %just example p = gf([1 0],n); % just example [quot,remd] = deconv(conv(a,b),p); Note that functions gfconv and gfdeconv exist, but Matlab recommends to use standard conv...

How to set up an array with related items

java,arrays,polynomials

First create a POJO class to store polynomial variables in the fields coefficient, variable, exponent. Then call them from another class; Here is the POJO class, I call it Element; public class Element { private double coefficient; private int exponent; private String variable; public Element(double coefficient, String variable, int exponent...

What is an efficient way of multiplying massive polynomials in Java?

java,matrix,polynomials

Maybe this idea will help you to solve your problem: int result = 1; int x = 2; int y = 3; Integer [][] polynomials = new Integer[x][y]; polynomials[0][0] = 1; polynomials[0][1] = 2; polynomials[0][2] = 3; polynomials[1][0] = 4; polynomials[1][1] = 5; polynomials[1][2] = 6; for(int i = 0;...

MATLAB polynomial fit selective powers

matlab,least-squares,polynomials

It sounds like you have the fitting toolbox and want to just remove a possible coefficient. If that's the case, here's a way to do it. %What is the degree of the polynomial (cubic) polyDegree = 3; %What powers do you want to skip (x^2 and x) skipPowers = [2,...

IPython, Ploting a Polynomial

plot,ipython,sympy,polynomials

Welcome to SO! The subs() method is not meant to be used with numpy arrays. lambdify() does what you want. Try: import numpy as np import matplotlib.pyplot as plt import sympy as sy sy.init_printing() # nice formula rendering in IPython x = sy.symbols("x", real=True) # the sample polynomial: pp =...

R_fitting a polynomial with a known intercept

r,intercept,polynomials

lm(y~-1+x+I(x^2)+offset(k)) should do it. -1 suppresses the otherwise automatically added intercept term x adds a linear term I(x^2) adds a quadratic term; the I() is required so that R interprets ^2 as squaring, rather than taking an interaction between x and itself (which by formula rules would be equivalent...

polynomial addition using linked list in java

java,linked-list,polynomials

Here's an add method that works: public static LinkedPoly add(LinkedPoly list1,LinkedPoly list2){ LinkedPoly addList=new LinkedPoly(); Node2 temp1=list1.head; Node2 temp3=temp1; Node2 temp2=list2.head; Node2 temp4=temp2; while(temp1.next!=null){ while(temp2.next!=null){ if(temp1.exp==temp2.exp){ addList.createList((temp1.coef+temp2.coef),temp1.exp); exponent+=temp1.exp; } temp2=temp2.next; } temp1=temp1.next; temp2=temp4; addList.print(); } String[] array=exponent.split(""); while(temp3!=null){ boolean exponentPresent = false; for(int...

Computing the powers of a polynomial f(x) modulo irreducible polynomial h(x) in MATLAB

matlab,polynomial-math,exponentiation,finite-field,polynomials

Try this u = f; for i=1:t [q{i},r{i}] = deconv(f,h); f = conv(f,u); end Your answer for each power will be in the cell array r....

Create a polynomial of arbitrary degree in python

python,polynomials

Yes, you can create an arbitrary degree polynomial, it will compute up to however many coefficients you give it. You want to make sure to give it d+1 coefficients if the user wants a polynomial of degree d. You can convince curve_fit to give it d+1 coefficients if you make...

Sorting a list of lists based on nth element, then n+1th element, etc

sorting,lisp,common-lisp,polynomials

If you have two criteria to sort by, you can first sort by the secondary, then stable-sort by the primary criterion: (stable-sort (sort polynomial #'< :key #'third) #'string< :key #'second) (You can compare symbols with string< because symbols are string designators.) If you have a more complicated function that defines...

C++: How to compute an integral with interval bounds?

c++,algorithm,integral,polynomials

A few pointers: Use std::vectors instead of pointers and new. (If you are new to C++, there are very few circumstances when you actually need to use new.) ComputeIntegral(double, double) will need to return a double, since it is obviously computing a definite integral. (The function you have at the...

Assign the pointer of one class object to another class object c++

c++,arrays,class,object,polynomials

You can define a get_head() function in Poly class Poly{ private: Node *head; public: Node * get_head() { return head; } }; and use it this way: polyhead = polynomial_array[n]->get_head(); ...

Polynomial over final field library

c++,polynomials,finite-field,galois-field

Looks like NTL is the solution. It gives comfortable implementation of GF(2^n) polynomials modulo some polynomial and easy work with matrices (inverse, solving, etc..)

Transferring code from notepad ++ to command prompt

java,arrays,enums,polynomials

You have two } too many here: if (rootAns == true) { System.out.println("Sorry - no roots were found in the specified interval."); } } } else { If you indent your code properly, it's easier to see these kinds of errors. Remove the two } that don't belong there: if...

Faster way to attach 2d polynomial coefficients to terms in Python?

python,sympy,polynomials

Constructing a sy.Poly would take a lot less time: using_loop : 43.56 using_P2 : 12.64 using_poly : 0.03 from timeit import default_timer as tc import numpy as np import sympy as sy from numpy.polynomial.polynomial import polyval2d as P2 def using_poly(coefficient_matrix, S=sy.S): order = coefficient_matrix.shape[0] x = sy.Symbol('x') y = sy.Symbol('y')...

polynomial fitting on spectral data

r,curve-fitting,raster,polynomials

Your question is not very clear, as you do not specify what you are fitting. I am guessing it is band number. You can do something like this. library(raster) b <- brick(system.file("external/rlogo.grd", package="raster")) b[[2]][125:225] <- NA s <- stack(b, flip(b, 'y')) names(s) <- paste0('b', 1:6) bands <- 1:6 f <-...

Tolerances, linalg.solv, polynom solve

python,numpy,mathematical-optimization,polynomials

The floating point arithmetic is leading you astray. If you look at the determinant of that matrix a, it's something incredibly small like 1.551864434916621e-51. If you compute the determinate with the entries as integers (and avoid floating point arithmetic weirdness) you'll see it's actually 0, and the rank of your...

How to apply a polynomial to a sequence

matlab,matrix,polynomials

The notation [i] means taking the coefficient of z^i. Notice that i runs only from 0 to l-d in the definition; so, the result of computation is empty if d is greater than l. Your example with d=4 and l=3 is not a valid input for this computation. In the...

Polynomial multiplication in M2(R)?

algorithm,matrix,fft,polynomials

You can not expect this method to work if your coefficient matrices do not commute with your matrix step. To get it working correctly, use the diagonal matrix corresponding to multiplication with the scalar exp(i*2*PI/M).

Algorithm for closed-form polynomial root finding

c++,numeric,polynomials

This isn't really answering your question but I think you can improve on what you've got since you currently have a 'loss of significance' problem when b^2 >> ac. In such cases, you end up with a formula along the lines of (-b + (b + eps))/(2 * a) where...

python polynomial package of multiple variables

python,math,scipy,polynomials

1),2) Use sympy from sympy import * x = Symbol('x') y = Symbol('y') z = Symbol('z') w = Symbol('w') u = Symbol('u') q = Symbol('q') e = Symbol('e') f = x**3 + x*y**4 + x*z**2*w + u*q**2*w*e**3 f2 = (f*f) F = integrate(f, x) G = integrate(f, y) 3) Curve...

Why does Sympy cut off polynomial terms with small coefficients?

python,sympy,polynomials,coefficients

I don't know why sympy truncates small coefficients when constructing a polynomial over reals, but it doesn't do this over rationals. So as a workaround, you can construct a polynomial with domain='QQ', extract coefficients, and then convert back to floats. Example using your polynomial: import sympy z_s = symbols('z_s') f...

Multiplying polynomials in Python with the use of dictionaries

python,dictionary,polynomials

Here's one approach that might work: for exponent1 in self.polynom: for exponent2 in other.polynom: this_exponent = exponent1 + exponent2 this_coeff = self.coefficient(exponent1) * other.coefficient(exponent2) try: mult[this_exponent] += this_coeff except KeyError: mult[this_exponent] = this_coeff That is, update the coefficient of the new power, and catch the Exception that is raised the...

Roots of a polynomial mod a prime

algorithm,sympy,polynomial-math,polynomials

This is pretty well studied, as mcdowella's comment indicates. Here is how the Cantor-Zassenhaus random algorithm works for the case where you want to find the roots of a polynomial, instead of the more general factorization. Note that in the ring of polynomials with coefficients mod p, the product x(x-1)(x-2)...(x-p+1)...

Find tangent points on a curve from a user-given point outside the curve

matlab,geometry,curve-fitting,polynomials

One possibility is to use numerical differentiation to find the tangent line at every point, and decide whether it passes "close enough" to the given point. However, one has to think hard about "close enough" to avoid getting either no matches or too many. Here is another approach: consider the...

“infinite type” error in haskell, cannot find whats wrong

haskell,polynomials

Slight problem with parentheses causing the type checker to infer an unexpected type. First, your code a bit reformatted: adecentarPolinomio :: Polinomio -> Polinomio adecentarPolinomio [email protected](Pol lista) = let f [email protected](k,n) l = if n == (snd $ head $ l) then ((k + fst $ head l), n) :...

Why does sympy.diff not differentiate sympy polynomials as expected?

python,sympy,polynomials

This appears to be a bug. You can get around it by calling diff directly on the Poly instance. Ideally calling the function diff from the top level sympy module should yield the same result as calling the method diff. In [1]: from sympy import * In [2]: from sympy.abc...