フィルターのクリア

Using the incremental search method or otherwise to locate one root of the function

8 ビュー (過去 30 日間)
John wick
John wick 2019 年 9 月 13 日
コメント済み: Adam 2019 年 9 月 13 日
Use Matlab's fzero function or your own method to locate all roots of the function,
f ( x ) = cos ( − 5 x ^3 + 6 x ^2 + 4 x − 3 )
on the interval [1,2] if they exist then plot the function on the interval marking the roots with red circles of size 3.
If there are no roots on your interval then use the incremental search method or otherwise to locate one root of the function and plot it with a red circle of size 3 along with the function.
I have arrived with the code down below but is there a way to add the one that says "If no roots" in the code below
f = @(x)cos(-5.*x.^3+6.*x.^2+4x-3);
fplot(f,[1,2]);
hold on;
for n = 1:0.1:2
k = fzero(f,n);
plot(k, 0,'ro','MarkerSize',3);
end
  3 件のコメント
John wick
John wick 2019 年 9 月 13 日
編集済み: John wick 2019 年 9 月 13 日
Thank you for the comment!
So as i should change, it should be something like this in order for it to answer the problem of if no roots. Other structure is fine so i only need to change the fzero part.
f = @(x)cos(-5.*x.^3+6.*x.^2+4.*x-3);
fplot(f,[1,2]);
hold on;
for n = 1:0.1:2
[k,fval,exitflag,output] = fzero(f,n);
plot(k, 0,'ro','MarkerSize',3);
end
Adam
Adam 2019 年 9 月 13 日
Well, you need to interpret that exitflag and react accordingly if it reports there was no result.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by