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

  • Thread starter Thread starter Electro
  • Start date Start date
  • Tags Tags
    Matlab Plotting
AI Thread Summary
The discussion revolves around plotting the function 1/(X^3 + X^2 + 1) in MATLAB, where the user encounters an error due to the function being undefined at X = -1.4656, resulting in division by zero. To resolve this, suggestions include defining a range for X values, selecting a number of points for plotting, initializing an axis vector and a results vector, and using a loop to calculate Y values while handling potential errors by assigning zero to undefined points. The conversation indicates that more experienced MATLAB users may offer improved solutions or code assistance.
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
Views
2K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
4
Views
4K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
3
Views
2K
Back
Top