Plotting Function 1/(X^3 + X^2 +1) in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter Electro
  • Start date Start date
  • Tags Tags
    Matlab Plotting
Click For Summary
SUMMARY

The discussion focuses on plotting the function 1/(X^3 + X^2 + 1) in MATLAB, highlighting an error due to division by zero at X = -1.4656. The user seeks assistance in visualizing this function, which is undefined at certain points. A step-by-step approach is provided, including defining the range, number of points, and using a loop to calculate values while handling potential errors. This method ensures that the plot can be generated without encountering undefined values.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Knowledge of polynomial functions and their properties
  • Familiarity with plotting techniques in MATLAB
  • Basic error handling in programming
NEXT STEPS
  • Learn how to implement error handling in MATLAB functions
  • Explore MATLAB's plotting functions for advanced visualizations
  • Study the concept of limits and discontinuities in mathematical functions
  • Investigate MATLAB's vectorization techniques to optimize calculations
USEFUL FOR

Mathematics students, MATLAB users, and engineers looking to visualize complex functions and handle undefined values in their plots.

Electro
Messages
48
Reaction score
0
Hi there,
I have a simple function and I want to plot it in MATLAB but i get an error.
Maybe someone can help. The function is of the type 1/(X^3 + X^2 +1)
I can plot a polynomial but I have no idea about the function above.
Thnx
 
Physics news on Phys.org
Electro said:
Hi there,
I have a simple function and I want to plot it in MATLAB but i get an error.
Maybe someone can help. The function is of the type 1/(X^3 + X^2 +1)
I can plot a polynomial but I have no idea about the function above.
Thnx
Your function is UNDEFINED (Illegal) at X=(-1.4656) because the denominator becomes 0 at this point which involves division by zero. If your graph includes this X value, that's probably the problem.


~~
 
Last edited:
You could do the following:

1. Decide on your range xmax, xmin
2. Decide on the number of points you want to plot (say N=1,000)
3. Declare an Axis vector with the axis points and a Y = zeros(1,N) vector to receive the results of the calculation
4. Use a loop to perform the calc y = ... from xmin to xmax in steps (xmax - xmin)/N and populate the Y vector. Include a check which says if the calc gives an error, put zero in that cell.
5. Plot Y vs Axis.

Others with more Matlab experience may have a much better solution but let me know if you want me to knock together some useable code.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K