In matlab grader it says i am trying to write a scrip instead of a function.
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
f = @(x) (2.*x.^3 + 3.*x-1) .* cos(x) - x;
[bisec_root, n, err] = bisection_method(f, -1, 1, 10E-5, 20)
matlab_root = fzero(f, 1)
x1 = -1: 0.1: 1;
y1 = f(x1);
plot(x1, y1);
function [c, n, err] = bisection_method(f, a, b, tol, N)
c = a;
n = 1;
err = 1;
while err > tol && n < N
x = (a+b)/2;
err = abs(x - c);
if f(a)/f(x) < 0 %get the sign
b = x;
else
a = x;
end
c = x;
n = n + 1;
end
% Output
% bisec_root = 0.43854
% n = 16
% err = 6.1035e-05
% matlab_root = 0.43857
5 comentarios
Adam Danz
el 14 de Sept. de 2019
The first non-commented line of your code needs to be,
function [c, n, err] = bisection_method(f, a, b, tol, N)
If this isn't clear, spend some time reading through this page,
Respuestas (1)
Cris LaPierre
el 23 de Sept. de 2019
Editada: Cris LaPierre
el 23 de Sept. de 2019
The "Solution script not found" sounds like an issue discovered in an update that was rolled out on the 13th. That issue has been addressed. Do you still see this error?
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!