In matlab grader it says i am trying to write a scrip instead of a function.

33 views (last 30 days)
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 Comments
Juan Gomez
Juan Gomez on 14 Sep 2019
I deleated the lines and matlab grader still says im trying to write a script.
Adam Danz
Adam Danz on 14 Sep 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,

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 23 Sep 2019
Edited: Cris LaPierre on 23 Sep 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?

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!