How can I plot the result of FZERO?

1 回表示 (過去 30 日間)
Nathanael
Nathanael 2011 年 10 月 13 日
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 Center および File ExchangeOptimization についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by