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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Stephen23
Stephen23 am 3 Mär. 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 am 3 Mär. 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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Torsten
Torsten am 3 Mär. 2024
Verschoben: Torsten am 3 Mär. 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

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by