MATLAB: How to plot the result of FZERO

fzerogeneral matlab usageMATLAB

I have this problem using fzero: Find the x-axis crossing of the function y=20*x^3+25 in range of -20 to 20. Plot the curve with the answers on it.
Can anyone assist me plotting the answers? My answer look like: fzero('20*x^3+25',-30) ans = -1.0772

Best Answer

  • If you plot the function in the range from -20:20, you can see, that it crosses the x-axis around -1.0772 (and probably nowhere else). If you need to plot the function, here's a possible way:
    x=-20:0.1:20; % '0.1' is an arbitrary increment dx
    In the current case the dx=0.1, and for plotting the -1.0772 you need to make this dx<0.0001, however, the full value the matlab gives is -1.077217345015942 (which is also rounded), thus theoretically, you would need to set your dx<10^-15. Plotting your answer does not make sense. You could put a text over the plot with your answer: