MATLAB Answers

0

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

Asked by Juan Gomez on 14 Sep 2019
Latest activity Edited by Cris LaPierre
on 23 Sep 2019
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

I did not say to move those lines below the function line: I said to delete them. You are required to submit a function, not a script.
I deleated the lines and matlab grader still says im trying to write a script.
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.

1 Answer

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

  0 Comments

Sign in to comment.