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

Click For Summary
SUMMARY

This discussion provides a step-by-step guide for plotting a fourth-degree polynomial in MATLAB. The equation discussed is f = 1.47*(x^4) - 10^7*(x) + 58.92*(10^6). Users must utilize the dot operator for element-wise operations when working with matrices, specifically using f = 1.47*(x.^4) - 10^7*(x) + 58.92*(10^6). The typical process involves creating a vector for x values, calculating corresponding y values, and then using the MATLAB plot function to visualize the graph.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of polynomial equations and their degrees
  • Knowledge of element-wise operations in MATLAB
  • Basic graphing techniques in MATLAB
NEXT STEPS
  • Learn about MATLAB's element-wise operations and the dot operator
  • Explore MATLAB's plotting functions and customization options
  • Study polynomial regression and fitting techniques in MATLAB
  • Investigate alternatives to MATLAB, such as Freemat for similar functionalities
USEFUL FOR

Students, engineers, and researchers who need to visualize polynomial equations using MATLAB or similar software tools.

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   Reactions: 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   Reactions: 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   Reactions: 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 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K