How to Plot a 4th Degree Polynomial in MATLAB: Step-by-Step Guide

In summary, the conversation is about plotting a Grade 4 equation in MATLAB. The equation provided is f = 1.47*(x^4)-10^7*(x)+58.92*(10^6), and it is advised to use the dot operator when working with a row/column matrix. The conversation also mentions the use of the MATLAB plot function and suggests a MATLAB clone called Freemat as an alternative.
  • #1
saeede-
9
0
hey everyone . I want to plot a Grade 4 equation in MATLAB. but don't know how to do. Can anyone guide me?

equation : f = 1.47*(x^4)-10^7*(x)+58.92*(10^6)
 
Physics news on Phys.org
  • #2
If your x is a row/column matrix you will need to add a . before multiplicative operations to make them element-by-element. In other words, if you have something like
Code:
x = 0:0.01:10;
then you will need to do
Code:
f = 1.47*(x.^4)-10^7*(x)+58.92*(10^6)
because Matlab does not understand what a row/column matrix to the power of 4 means.
 
  • Like
  • Love
Likes jedishrfu and saeede-
  • #3
The dot operator is something often missed by newbies to matlab.
 
  • #4
saeede- said:
hey everyone . I want to plot a Grade 4 equation in MATLAB. but don't know how to do. Can anyone guide me?

equation : f = 1.47*(x^4)-10^7*(x)+58.92*(10^6)
Your post confused me -- I thought this might be an equation given to someone in the fourth grade. In English we call such equations fourth degree, not Grade 4.
 
  • #5
Orodruin said:
If your x is a row/column matrix you will need to add a . before multiplicative operations to make them element-by-element.
I suspect, without much evidence, that the OP merely wants to graph the equation, where x is a real number.
 
  • #6
Mark44 said:
I suspect, without much evidence, that the OP merely wants to graph the equation, where x is a real number.
Yes, and the typical way to do that in MATLAB is to first create a vector x containing the x values, then using a function as described above to get the corresponding y-values. Then using the MATLAB plot function, which takes the vectors of x and y values as input. This is why you need the dot in the operator in the second step.
 
  • Like
Likes jedishrfu
  • #7
Plot example:
x = [0:100]
y = x .* x
plot(x,y)

Also there is a nice MATLAB clone called Freemat which supports the core functionality of MATLAB.

http://freemat.sourceforge.net/
 
  • Like
  • Informative
Likes PhDeezNutz, berkeman and Orodruin
  • #8
Mark44 said:
Your post confused me -- I thought this might be an equation given to someone in the fourth grade. In English we call such equations fourth degree, not Grade 4.
yes :)) I'm not an English person . so it's normal having such mistakes.
 

1. How do I input a 4th degree polynomial into MATLAB?

To input a 4th degree polynomial into MATLAB, you can use the "polyfit" function. This function takes in two arguments: the x-values and the y-values of the polynomial. For example, if your polynomial is y = 3x^4 + 5x^3 + 2x^2 + 7x + 1, you would input the x-values and y-values as separate vectors, and then use the polyfit function to obtain the coefficients of your polynomial.

2. How do I plot a 4th degree polynomial in MATLAB?

To plot a 4th degree polynomial in MATLAB, you can use the "plot" function. First, you need to create a vector of x-values over the range you want to plot. Then, you can use the "polyval" function to evaluate your polynomial at each of these x-values. Finally, use the "plot" function to plot the x-values against the evaluated y-values.

3. Can I customize the appearance of my 4th degree polynomial plot in MATLAB?

Yes, you can customize the appearance of your plot by using additional arguments in the "plot" function. For example, you can change the color, line style, and marker style of your plot. You can also add a title, labels for the x and y axes, and a legend to your plot.

4. How do I find the roots of a 4th degree polynomial in MATLAB?

To find the roots of a 4th degree polynomial in MATLAB, you can use the "roots" function. This function takes in the coefficients of your polynomial as an argument and returns the complex roots of the polynomial. You can also use the "fzero" function to find a specific root by providing an initial guess.

5. Can I use MATLAB to solve equations involving 4th degree polynomials?

Yes, you can use MATLAB to solve equations involving 4th degree polynomials by using the "solve" function. This function takes in two arguments: the equation to solve and the variable to solve for. It will return the solutions to the equation as a vector. You can also use the "fzero" function to solve for a specific root of the polynomial.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
748
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
Back
Top