My while loop is garbage, teacher wont help, and I dunno jack about coding!

Alrighty, so I need to code the bisection method to evaluate a fluid dynamics equation.
I've been coding MATlab for ohhhhhh about 3 weeks now and this is wayyyyy above my skill-set.
but here's what I got, I've gotten it to actually work but gives the wrong answer, I've gotten it to run for what seems like an infinite loop
and i've gotten it to loop once and never again, I'm stuck and I'm just not educated enough to fix it.
Also built in MATlab functions are a no-no so it has to be the old school no shortcut's way to do things. no dsolve or syms or what have you.
Please help!
clc; clear all;
%Assignments from given data
d=3.612; %Density in kg/m^3
v=20; %Velocity in m/s
m=.00001825; %Dynamic Viscosity in N*s/m^2
l=20; %Length in meters
D=.5; %Diameter in meters
n=.0001; %Surface roughness of pipe in meters
Re=(d*v*D)/m;
%Assignments from me
a=.000001;
b=.999999;
EA=.001;
fa=(-2.0*log10(((n/D)/3.7)+(2.51/(Re*sqrt(a)))))-(1/(sqrt(a)));
fb=(-2.0*log10(((n/D)/3.7)+(2.51/(Re*sqrt(b)))))-(1/(sqrt(b)));
while abs((b-a)/b)>EA
c=(a+b)/2;
fc=(fa+fb)/2;
if fa*fc<0
b=c;
fb=fc;
elseif fb*fc<0
a=c;
fa=fc;
else
break
end
end
f=fc;
fprintf('f= %8.6d',f);

댓글 수: 2

Well I resisted the urge to throw my laptop into traffic ( and myself with it) and got it figured out!
Thanks anyways
sorry if I wasted anyones time.
You wasted nobody’s time. It would have helped if you had described what you want your programme to do, what it was doing instead, and specifically what was not working. We have no idea.
Please consider doing that if you again need help here.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2019년 2월 23일

댓글:

2019년 2월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by