Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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 comentarios
Terry Poole
Terry Poole el 23 de Feb. de 2019
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.
Star Strider
Star Strider el 23 de Feb. de 2019
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by