Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Plotting in Matlab

  1. Mar 2, 2005 #1
    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.
  2. jcsd
  3. Mar 2, 2005 #2


    User Avatar
    Science Advisor

    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: Mar 2, 2005
  4. Mar 3, 2005 #3
    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.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Plotting Matlab Date
Matlab Plotting Coordinate Transformations in Matlab Feb 12, 2018
Matlab Plotting animations (time-evolution) Jan 17, 2018
Does anyone had this plotting problem with MATLAB? Dec 23, 2017
Matlab Matlab's plot command Nov 30, 2017
Matlab Matlab -- how to make a smooth contour plot? Jun 28, 2017