How can I plot the result of FZERO?

1 次查看(过去 30 天)
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
Thanks

采纳的回答

Naz
Naz 2011-10-13
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
y=20*x.^3+25;
plot(x,y);
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:
text(0,.5*10^5,'-1.0772')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by