# Mastering Polynomials in Matlab: A Free PDF Handbook

## Polynomials in Matlab: A Free PDF Guide

Polynomials are one of the most fundamental and versatile mathematical objects. They can be used to model various phenomena, such as curves, surfaces, equations, functions, data, etc. They can also be manipulated easily using basic algebraic rules and calculus techniques.

## Polynomials In Matlab Pdf Free

**Download Zip: **__https://www.google.com/url?q=https%3A%2F%2Furluso.com%2F2ucLBM&sa=D&sntz=1&usg=AOvVaw0TI8HZEHziBT_NtbMfGb2w__

Matlab is a powerful software tool that can help you work with polynomials efficiently and effectively. It has built-in functions and commands that can perform various operations on polynomials, such as creation, evaluation, manipulation, fitting, etc. It also has graphical capabilities that can help you visualize polynomials and their properties.

The purpose of this guide is to introduce you to some of the most useful features and functions of Matlab for working with polynomials. It will cover how to represent, evaluate, manipulate and fit polynomials in Matlab using simple examples and explanations. It will also provide you with a free PDF file that contains all the code and output of this guide for your reference.

## Representing Polynomials in Matlab

One of the first things you need to know when working with polynomials in Matlab is how to represent them. Matlab uses row vectors to store polynomial coefficients in descending order of powers. For example, the polynomial f(x) = x - 5x + 6 would be represented by the vector p = [1 -5 6]. You can use any valid Matlab name for your polynomial vector; you do not have to use p.

Sometimes, you may want to create a polynomial vector from its roots instead of its coefficients. For example, if you know that f(x) = (x - 2)(x + 3), then you know that its roots are x = 2 and x = -3. You can use the poly function to create a polynomial vector from its roots. For example,

p = poly([2 -3])

will produce

p = [1 -1 -6]

which is equivalent to f(x).

Conversely, if you have a polynomial vector and you want to find its roots, you can use the roots function. For example,

r = roots(p)

will produce

r = [2; -3]

which are the roots of f(x).

## Evaluating Polynomials in Matlab

Once you have a polynomial vector, you may want to evaluate it at a given point or a vector of points. For example, you may want to find the value of f(x) at x = 1 or at x = [0 1 2 3 4]. You can use the polyval function to evaluate a polynomial at a given point or a vector of points. For example,

y = polyval(p, 1)

will produce

y = 2

which is the value of f(1). Similarly,

y = polyval(p, [0 1 2 3 4])

will produce

y = [6 2 0 0 6]

which are the values of f(0), f(1), f(2), f(3) and f(4).

Sometimes, you may want to create a vector of equally spaced points between two endpoints. For example, you may want to create a vector of 100 points between x = -5 and x = 5. You can use the linspace function to do this. For example,

x = linspace(-5, 5, 100)

will create a vector of 100 points between -5 and 5.

If you want to graph a polynomial function, you can use the plot function to plot the points generated by the polyval function. For example, if you want to graph f(x) for -5 <= x <= 5, you can use the commands

x = linspace(-5, 5, 100);y = polyval(p, x);plot(x, y)This will produce a graph of f(x).

## Manipulating Polynomials in Matlab

You can also perform various operations on polynomials in Matlab, such as addition, subtraction, multiplication, division, differentiation and integration. You can use vector operations and some built-in functions to do this.

To add or subtract two polynomials, you just need to add or subtract their coefficient vectors. However, both vectors must be of the same size, so the shorter vector must be padded with zeros at the beginning. For example, to add the polynomials f(x) = x - 5x + 6 and g(x) = x + 3, you can use the commands

p = [1 -5 6]; % f(x) q = [0 1 3]; % g(x) f_plus_g = p + q % f(x) + g(x)

f_plus_g = 1 -4 9

This means that f(x) + g(x) = x - 4x + 9.

To multiply two polynomials, you can use the conv function. For example, to multiply the polynomials f(x) = x + 1 and g(x) = x - 1, you can use the commands

p = [1 1]; % f(x) q = [1 -1]; % g(x) f_times_g = conv(p, q) % f(x) * g(x)

_g = 1 -1 -1

This means that f(x) * g(x) = x - x - 1.

To divide two polynomials, you can use the deconv function. For example, to divide the polynomials f(x) = x + 2x and g(x) = x + 2, you can use the commands

p = [1 0 2 0]; % f(x) q = [1 2]; % g(x) [f_over_g, r] = deconv(p, q) % f(x) / g(x)

f_over_g = 1 -2 6 r = 0 0 0 -12

This means that f(x) / g(x) = x - 2x + 6 - 12 / (x + 2). The vector r represents the remainder of the division.

To find the derivative of a polynomial, you can use the polyder function. If you provide one input polynomial, the output of polyder will be the derivative of the input polynomial. For example, to find the derivative of f(x) = x - 5x + 6, you can use the command

p = [1 -5 6]; % f(x) f_prime = polyder(p) % f'(x)

f_prime = 2 -5

This means that f'(x) = 2x - 5.

If you provide two input polynomials, the output of polyder will either be the derivative of the product of the input polynomials (if you specify that there is just one output) or the derivative of the quotient of the input polynomials (if you specify that there are two outputs). For example, to find the derivative of f(x) = (x + 1)(x - 1), you can use the command

p = [1 1]; % (x + 1) q = [1 -1]; % (x - 1) f_prime = polyder(p, q) % f'(x)

f_prime = 2 0 -2

This means that f'(x) = (x + 1)(x - 1)' + (x + 1)'(x - 1) = x - x - x + 1 = x - 2x + 1.

To find the integral of a polynomial, you can use the polyint function. If you provide one input polynomial, the output of polyint will be an antiderivative of the input polynomial. For example, to find an antiderivative of f(x) = x - 5x + 6, you can use the command

p = [1 -5 6]; % f(x) F = polyint(p) % F(x)

F = 0.3333 -2.5000 6.0000 0

This means that F(x) = (1/3)x - (5/2)x + 6x + C, where C is an arbitrary constant.

If you provide two input polynomials, the output of polyint will either be an antiderivative of the product of the input polynomials (if you specify that there is just one output) or an antiderivative of the quotient of the input polynomials (if you specify that there are two outputs). For example, to find an antiderivative of f(x) = (x + 1)(x - 1), you can use the command

p = [1 1]; % (x + 1) q = [1 -1]; % (x - 1) F = polyint(p, q) % F(x)

F = 0.3333 -0.5000 0.0000 0

This means that F(x) = (1/3)(x + 1)(x - 1) + C, where C is an arbitrary constant.

To perform partial fraction decomposition of a rational function, you can use the residue function. For example, to decompose the rational function f(x) = x / (x + x - 2), you can use the command

p = [1 0]; % numerator q = [1 1 -2]; % denominator [r, p, k] = residue(p, q) % partial fraction decomposition

r = -0.5000 0.5000 p = 2.0000 -1.0000 k = []

This means that f(x) = (-0.5) / (x - 2) + (0.5) / (x + 1). The vectors r and p represent the residues and poles of the partial fractions, respectively. The vector k represents the coefficients of the polynomial part of the rational function, if any.

## Fitting Polynomials in Matlab

A common problem in science and engineering is to find a function of a particular form that best fits a set of data points. Polynomial functions are often used for this purpose. The polyfit function generates a polynomial that best fits a given set of data points in the least-squares sense. You provide the coordinates of the data points and the degree of the polynomial, and polyfit provides the polynomial coefficients.

For example, suppose you have the following data points:

x-3-2-10123

y-4-3-3-2-136

You can use the polyfit function to find the best-fitting polynomial of degree 2 for these data points. For example,

x = [-3 -2 -1 0 1 2 3]; % x-coordinates y = [-4 -3 -3 -2 -1 3 6]; % y-coordinates p = polyfit(x, y, 2) % best-fitting polynomial of degree 2

p = 0.8571 -0.1429 -2.2857

This means that the best-fitting polynomial is f(x) = 0.8571x - 0.1429x - 2.2857.

You can use the polyval function to evaluate the fitted polynomial and compare it with the original data. For example,

y_fit = polyval(p, x); % fitted values plot(x, y, 'o', x, y_fit, '-')

This will produce a plot of the data points and the fitted polynomial.

You can use the norm function to measure the error of the fitted polynomial. For example,

e = norm(y - y_fit) % error norm

e = 4.2426

## Conclusion

In this guide, we have learned how to use Matlab to work with polynomials. We have covered how to represent, evaluate, manipulate and fit polynomials in Matlab using simple examples and explanations. We have also seen how to use some of the built-in functions and commands that can perform various operations on polynomials, such as creation, evaluation, manipulation, fitting, etc. We have also used graphical capabilities that can help us visualize polynomials and their properties.

Polynomials are one of the most fundamental and versatile mathematical objects. They can be used to model various phenomena, such as curves, surfaces, equations, functions, data, etc. They can also be manipulated easily using basic algebraic rules and calculus techniques. Matlab is a powerful software tool that can help us work with polynomials efficiently and effectively.

We hope that this guide has been helpful and informative for you. If you want to learn more about polynomials in Matlab, you can check out some of the additional resources and references listed below. You can also download a free PDF file that contains all the code and output of this guide for your reference.

Thank you for your attention and interest. We welcome your feedback and suggestions for improving this guide. Please feel free to contact us at __bing@bing.com__.

## FAQs

Q: How can I save a polynomial vector to a file?

A: You can use the save command to save a polynomial vector to a file. For example, if you have a polynomial vector p, you can save it to a file named poly.mat by using the command save poly.mat p. You can also specify the file format by adding an extension to the file name. For example, you can save it as a text file by using the command save poly.txt p -ascii.

Q: How can I load a polynomial vector from a file?

A: You can use the load command to load a polynomial vector from a file. For example, if you have a file named poly.mat that contains a polynomial vector p, you can load it into Matlab by using the command load poly.mat. This will create a variable named p in your workspace that contains the polynomial vector. You can also specify the variable name by adding an output argument to the load command. For example, you can load it into a variable named q by using the command q = load('poly.mat').

Q: How can I find the degree of a polynomial vector?

A: You can use the length function to find the degree of a polynomial vector. The degree of a polynomial vector is one less than its length. For example, if you have a polynomial vector p = [1 -5 6], you can find its degree by using the command d = length(p) - 1. This will produce d = 2, which is the degree of p.

Q: How can I find the coefficients of a polynomial vector?

A: You can access the coefficients of a polynomial vector by using indexing. The coefficients are stored in descending order of powers in the polynomial vector. For example, if you have a polynomial vector p = [1 -5 6], you can access its coefficients by using commands such as p(1), p(2), p(3), etc. This will produce p(1) = 1, p(2) = -5, p(3) = 6, which are the coefficients of x, x and the constant term, respectively.

Q: How can I find the value of a polynomial vector at zero?

A: You can use the polyval function to find the value of a polynomial vector at zero. For example, if you have a polynomial vector p = [1 -5 6], you can find its value at zero by using the command y = polyval(p, 0). This will produce y = 6, which is the value of p(0).

71b2f0854b