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

AI Thread Summary
To plot the fourth-degree equation f = 1.47*(x^4) - 10^7*(x) + 58.92*(10^6) in MATLAB, it's essential to use element-wise operations when dealing with matrices. Specifically, when defining the equation, the dot operator should be used for exponentiation and multiplication, as in f = 1.47*(x.^4) - 10^7*(x) + 58.92*(10^6). This ensures MATLAB correctly interprets the operations for each element in the matrix. The typical process involves creating a vector for x values, calculating the corresponding y values using the equation, and then plotting them with the MATLAB plot function. Additionally, Freemat is mentioned as a MATLAB alternative that supports similar functionalities.
saeede-
Messages
8
Reaction score
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
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-
The dot operator is something often missed by newbies to matlab.
 
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.
 
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.
 
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
[CODE lang="matlab" title="Plot example"]x = [0:100]
y = x .* x
plot(x,y)[/CODE]

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
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.
 

Similar threads

Replies
2
Views
3K
Replies
10
Views
3K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
1
Views
4K
Replies
2
Views
2K
Replies
4
Views
3K
Back
Top