How to use fnzeros to find the zeros of a function?
6 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
Yatin
2013 年 10 月 15 日
編集済み: Yatin
2013 年 10 月 15 日
Hi,
The fnzeros function requires the inputs to be in a specific format as it is a function that works on splines and is a part of the Curve Fitting toolbox. You can however use " fzero " function to find roots iteratively in a loop until your root does not exceed the maximum limit of the range. So once you get the first zero(root), you can increment it by certain value to get the next zero. In this case 0.6 seems to be a reasonable guess. You can then insert all the roots in a vector. There are totally 33 zeros in this case but the above code finds only 27. So this is just a close approximation
A sample test code is as below:
imax = 10;
imin = -10;
fun = @(x)sin(5*x)+sin(2*x);
allZeros = [];
aZero1 = 0;
tempZero1 = imin;
while(tempZero1 <= imax)
aZero1 = fzero(fun, tempZero1);
tempZero1 = aZero1+ 0.6;
allZeros = [allZeros, aZero1];
end
allZeros = unique(allZeros);
0 件のコメント
その他の回答 (1 件)
Matt J
2013 年 10 月 15 日
編集済み: Matt J
2013 年 10 月 15 日
Looks like you're meant to form a spline approximation to y=sin(x*5)+sin(x*2) using spmak and then apply fnzeros to get the zeros. You will probably want to use a small knot spacing and test agreement with the original y(x) via some plots.
Theoretically, it's not a bulletproof way of getting the zeros. A bulletproof method can't rely exclusively on numerical solvers like fzero or fnzero. It would require some prior analysis determine the minimal spacing between solutions, but as a homework exercise, I guess your instructor doesn't care.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spline Postprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!