Ploting a function and its roots

6 ビュー (過去 30 日間)
Harel Harel Shattenstein
Harel Harel Shattenstein 2018 年 7 月 5 日
コメント済み: Star Strider 2018 年 7 月 5 日
f=@(x)x.^2-5*sin(x);
[p1,p2]=fzero(f,1,[-1,3])
fplot(f1,[-1,3])
Can I "draw" the roots p1,p2 in the same function fplot?

採用された回答

Star Strider
Star Strider 2018 年 7 月 5 日
The fzero function will only return one value for each initial estimate. You need to provide different initial estimates in different calls to it, if you want other roots. (For several roots, this usually requires a for loop.) Plotting the results is then straightforward.
Try this:
f=@(x)x.^2-5*sin(x);
p1 = fzero(f,1);
p2 = fzero(f,5);
fplot(f,[-1,3])
hold on
plot([p1,p2], [0 0], 'p')
hold off
  2 件のコメント
Harel Harel Shattenstein
Harel Harel Shattenstein 2018 年 7 月 5 日
編集済み: Harel Harel Shattenstein 2018 年 7 月 5 日
I can use fsolve too?
Star Strider
Star Strider 2018 年 7 月 5 日
Yes. However it is subject to the same initial estimate constraints, so that different initial estimates can result in different zeros and different parameter estimates, at least in my experience. The difference is that fsolve (link) finds parameters defining roots of systems of functions, and is not limited to single functions, as is fzero.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDirect Search についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by