It keeps giving me an error on line 4, saying I'm missing input arguments but I have everything defined?

2 views (last 30 days)
function root = BisectionRoot(Q,q,R,F,z1,z2)
tol = 1e-6;
err = 1.0;
z = (z1 + z2)/2;
fz = Fun(Q,q,R,F,z);
fz1 = Fun(Q,q,R,F,z1);
fz2 = Fun(Q,q,R,F,z2);
while err > tol
if fz1 < 0.0 & fz2 > 0.0
if fz > 0.0
z2 = z;
else
z1 = z;
end
elseif fz1 > 0.0 & fz2 < 0.0
if fz < 0.0
z2 = z;
else
z1 = z;
end
else
disp('The given interval does not contain the root.');
break;
end
z = (z1 + z2)/2;
err = abs(z - z1);
fz = Fun(Q,q,R,F,z);
fz1 = Fun(Q,q,R,F,z1);
fz2 = Fun(Q,q,R,F,z2);
end
root = z;
end
  4 Comments
Stephen23
Stephen23 on 3 Mar 2024
"I just pressed the run button once I finished writing it"
So precisely what values do you expect MATLAB to use for the inputs Q,q,R,F,z1,z2 ?
Patrick
Patrick on 3 Mar 2024
Q = 9.4e-6;
q = 2.4e-5;
R=0.1;
F=(Q*q*z) .*((1-z)./(sqrt(z.^2+R.^2)))/(2*epsilon);
epsilon= 0.885e-12;
So would I just add these values to my code?

Sign in to comment.

Accepted Answer

Torsten
Torsten on 3 Mar 2024
Moved: Torsten on 3 Mar 2024
Q = 9.4e-6;
q = 2.4e-5;
R=0.1;
epsilon= 0.885e-12;
F=@(z)(Q*q*z) .*((1-z)./(sqrt(z.^2+R.^2)))/(2*epsilon);
z1 = 0.5;
z2 = 2;
root = BisectionRoot(F,z1,z2)
function root = BisectionRoot(Fun,z1,z2)
tol = 1e-6;
err = 1.0;
z = (z1 + z2)/2;
fz = Fun(z);
fz1 = Fun(z1);
fz2 = Fun(z2);
while err > tol
if fz1 < 0.0 & fz2 > 0.0
if fz > 0.0
z2 = z;
else
z1 = z;
end
elseif fz1 > 0.0 & fz2 < 0.0
if fz < 0.0
z2 = z;
else
z1 = z;
end
else
disp('The given interval does not contain the root.');
break;
end
z = (z1 + z2)/2;
err = abs(z - z1);
fz = Fun(z);
fz1 = Fun(z1);
fz2 = Fun(z2);
end
root = z;
end

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!