Evaluating polynomials in Matlab

In summary, the conversation discusses different methods of working with polynomials in a symbolic system, including defining them as symbols or matrices. The use of the subs function is recommended for evaluating symbolic expressions, and the polyval command is suggested for evaluating polynomials at a specific point.
  • #1
qubits135
2
0
I defined x as a syms, then work with polynomials involving x. But then I can't find an evaluation command for these polynomials at some x value. Anyone knows how I can get it to work? Thank you in advance.

There's another system where you can define polynomials just like matrices, e.g. x^2+1 as [1 0 1]. But they only have elementary manipulation, and it becomes really cumbersome doing integral or derivative. (that was why I went the traditional way, which is the one mentioned above).

Thanx
 
Physics news on Phys.org
  • #3
The command polyval(h,x), where 'h' is a vector of the coefficients of an nth degree polynomial, evaluates a polynomial at each point 'x'.
 
  • Like
Likes FactChecker

What is a polynomial?

A polynomial is a mathematical expression consisting of variables and coefficients, usually written in the form of a sum of terms. Each term contains a variable raised to a non-negative integer power, and the coefficients are constants.

How do I evaluate a polynomial in Matlab?

To evaluate a polynomial in Matlab, you can use the built-in function 'polyval'. This function takes two inputs: the coefficients of the polynomial and the value(s) at which you want to evaluate the polynomial. It returns the corresponding value(s) of the polynomial.

Can I evaluate a polynomial with complex coefficients in Matlab?

Yes, you can evaluate a polynomial with complex coefficients in Matlab. The 'polyval' function can handle complex numbers as inputs, and will return complex numbers as outputs if the polynomial has complex coefficients.

How do I plot a polynomial in Matlab?

To plot a polynomial in Matlab, you can use the 'plot' function. First, create a vector of x-values at which you want to evaluate the polynomial. Then, use the 'polyval' function to evaluate the polynomial at each of these x-values. Finally, use the 'plot' function to plot the x-values against the corresponding y-values.

What are some common errors when evaluating polynomials in Matlab?

Some common errors when evaluating polynomials in Matlab include using incorrect coefficients or values as inputs, forgetting to use the 'polyval' function, and not defining the correct x-values for plotting. It is important to double check your inputs and syntax to avoid these errors.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Linear and Abstract Algebra
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • Differential Equations
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top