It keeps giving me an error on line 4, saying I'm missing input arguments but I have everything defined?
2 ビュー (過去 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
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 ?
採用された回答
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 Center および File Exchange で Performance and Memory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!