Help with Matlab function

11视图(30天)
Lavorizia Vaughn
Lavorizia Vaughn on 29 Sep 2021
hello,
i have to implement a MATLAB function findmanyzeros of the form function p = findmanyzeros(f, a, b, n, which finds zeros in the interval [ a, b ] 使用以下策略:
1.计算n +1 equidistant points x k,k =0 ,...,n , between a and b
2. For k = 1 ,...,n , if f ( x k ) f ( x k 1 ) have different signs, compute a zero using findzero
3. The output vector p should contain all the computed zeros
my code is as follows:
functionp = findmanyzeros(f, a, b, n, tol)
n=n+1;
fork = 1:n
iff(xk)*f(xk-1)<0
findzero(f);
end
end
p
my code is wrong and i could really appriciate some help, thanks.

Accepted Answer

扬
on 29 Sep 2021
Edited: on 30 Sep 2021
This homework question contains useful instructions already:
" Compute n+1 equidistant points xk , k=0,...,n, between a and b "
您已经省略了此步骤。使用命令 linspace() to solve it and assign the output to the variable x.
Then you can use f(x(k)) and f(x(k+1)).
I guess, that calling findzero needs the variable tol 。将此功能的输出分配给P(k)。
4条评论
Lavorizia Vaughn
Lavorizia Vaughn on 30 Sep 2021
是的,我的文件findzero命名为错误。谢谢您的帮助。

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

开始狩猎!