Polynomials in Matlab - Plotting Results

In summary, polynomials in Matlab are mathematical expressions used to represent relationships or functions in various fields. To plot polynomial results, use the plot function and customize the graph. Multiple polynomials can be plotted in the same graph using the hold on and hold off functions. The roots of a polynomial can be found using the roots function and operations such as addition, subtraction, and multiplication can be performed on polynomials using the standard arithmetic operators or built-in functions. The polyder and polyint functions can also be used to differentiate and integrate polynomials.
  • #1
ineedhelpnow
651
0
View attachment 5037

Code:
y = [0.053 1.477 1.970 3.279 4.153 4.934 5.178 5.828 6.082 6.484]; % data
coef = polyfit(x,y,3) 
X=0:.1:9;
Y=polyval(coef,X);
plot(x,y,'o',X,Y)

that's my code. did i do it right?
 

Attachments

  • 1.png
    1.png
    16.9 KB · Views: 68
Physics news on Phys.org
  • #2
You need to define your $x$ values. This should be right:

Code:
y = [0.053 1.477 1.970 3.279 4.153 4.934 5.178 5.828 6.082 6.484]; % data
x = [0 1 2 3 4 5 6 7 8 9];
coef = polyfit(x,y,3) 
X=0:.1:9;
Y=polyval(coef,X);
plot(x,y,'o',X,Y)

Output:

View attachment 5038

You can add a title, legend, and axis labels if you want, using [m]title()[/m], [m]legend()[/m], [m]xlabel()[/m], [m]ylabel()[/m], respectively.
 

Attachments

  • interpolation.PNG
    interpolation.PNG
    5.2 KB · Views: 63
  • #3
i cut that part of the code out by mistake but i have it in there. i see it's the same graph though. thanks rido!
 

Related to Polynomials in Matlab - Plotting Results

1. What are polynomials in Matlab?

Polynomials in Matlab are mathematical expressions that involve variables and coefficients, and only use operations such as addition, subtraction, and multiplication. They are commonly used to represent relationships or functions in different fields of science and engineering.

2. How do I plot polynomial results in Matlab?

To plot polynomial results in Matlab, you can use the plot function. First, define the polynomial expression using the variables and coefficients. Then, use the plot function to plot the polynomial over a specified range of values. You can also customize the plot by adding labels, titles, and adjusting the appearance of the graph.

3. Can I plot multiple polynomials in the same graph in Matlab?

Yes, you can plot multiple polynomials in the same graph in Matlab by using the hold on and hold off functions. These functions allow you to plot multiple expressions on the same graph without overwriting the previous one. You can also specify the color and style of each polynomial to differentiate them.

4. How can I find the roots of a polynomial in Matlab?

To find the roots of a polynomial in Matlab, you can use the roots function. This function takes the coefficients of the polynomial as input and returns the roots in a vector. If the polynomial has multiple roots, they will be listed as repeated values in the vector. You can also plot the roots on the polynomial graph to visualize their location.

5. Can I perform operations on polynomials in Matlab?

Yes, you can perform operations on polynomials in Matlab such as addition, subtraction, and multiplication. These operations can be done using the standard arithmetic operators or built-in functions like polyadd, polysub, and polymult. Additionally, you can also differentiate and integrate polynomials using the polyder and polyint functions respectively.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • Calculus and Beyond Homework Help
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
Back
Top