# My code is about finding head value using bisection or false error method .But its showing parse error for xl=input("the lower value");i don't know how to solve it...

1 view (last 30 days)
Atia Ashrafy on 22 Jun 2022
Commented: KSSV on 22 Jun 2022
function h = formula(n)
%Input the value of v,g,H,L,t
v=5;
g=9.81;
L=4;
t=2.5;
s=sqrt(2*g*n);
h = v -( s*tanh((t*s)/2*L));
end
%Input the value of lower and upper limit
xl=input("The lower value xl=");
xu=input("The upper value xu=");
es=0.01;
xold=0.00;
if formula(xl)*formula(xu)>0
fprintf("The value of H can not be calculated");
else
d=input("For the value of head by bisection method press 1 and for false position method press 2 for d,so d= ");
if d==1
xr=(xl+xu)/2;
else
xr=(((xu*formula(xl))-(xl*formula(xu))) /(formula(xl)-formula(xu))) ;
end
if (d==1&&d==2)
for i=1:100
if formula(xl)*formula(xr)<0
xu=xr;
elseif formula(xl)*formula(xr)>0
xl=xr;
else
break;
end
end
if abs((xr-xold)/xr)<=es
end
xold=xr;
end
fprintf("Value of head in this method is %f",xr);
end

KSSV on 22 Jun 2022
You have to either copy the function below the main code or copy the function into a different mfile and then run the main code.
Try running the below code.
%Input the value of lower and upper limit
xl=input("The lower value xl=");
xu=input("The upper value xu=");
es=0.01;
xold=0.00;
if formula(xl)*formula(xu)>0
fprintf("The value of H can not be calculated");
else
d=input("For the value of head by bisection method press 1 and for false position method press 2 for d,so d= ");
if d==1
xr=(xl+xu)/2;
else
xr=(((xu*formula(xl))-(xl*formula(xu))) /(formula(xl)-formula(xu))) ;
end
if (d==1&&d==2)
for i=1:100
if formula(xl)*formula(xr)<0
xu=xr;
elseif formula(xl)*formula(xr)>0
xl=xr;
else
break;
end
end
if abs((xr-xold)/xr)<=es
end
xold=xr;
end
fprintf("Value of head in this method is %f\n",xr);
end
function h = formula(n)
%Input the value of v,g,H,L,t
v=5;
g=9.81;
L=4;
t=2.5;
s=sqrt(2*g*n);
h = v -( s*tanh((t*s)/2*L));
end
##### 2 CommentsShowHide 1 older comment
KSSV on 22 Jun 2022
Thanks is accepting/ voting the answer.