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

1 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2024-3-3
"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 2024-3-3
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?

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2024-3-3
移动:Torsten 2024-3-3
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by