Help with a vector
古いコメントを表示
Hello. I have come up with the following code:
function p = findmanyzeros(f, a, b, n, tol)
x = a + (b-a)*(0:n)/n;
fx = f(x);
p = [];
for i = 1:n
if sign(fx(i)) ~= sign(fx(i+1))
p(end+1) = findzero(f, x(i), x(i+1), tol);
end
end
My instructions were to Implement a MATLAB function findmanyzeros of the form function p=findmanyzeros(f, a, b, n, tol)
which finds zeros in the interval [a, b] using the following strategy:
1. Compute n+1 equidistant points xk, k=0,...,n, between a and b
2. For k = 1,...,n, if f(xk) and f(xk−1) have different signs, compute a zero using findzero
3. The output vector p should contain all the computed zeros
5 件のコメント
Cris LaPierre
2021 年 9 月 30 日
Sorry if I missed it, but what is your question?
Lavorizia Vaughn
2021 年 9 月 30 日
Jan
2021 年 9 月 30 日
Whenever you mention an error in the forum, post a copy of the complete error message. It is much easier to solve an error that to guess, what the error is.
Lavorizia Vaughn
2021 年 9 月 30 日
Lavorizia Vaughn
2021 年 9 月 30 日
編集済み: Cris LaPierre
2021 年 9 月 30 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Mathematics and Optimization についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!