I am trying to use the bisection method to optimize the cost of the pipeline, but I can't get a value for f(a)? What am I doing wrong with my while loop or if statement?
function [x] = myPipeBuilder(C_ocean, C_land, L, H)%L=length of x, C_ocean=cost of pipeline in ocean, C_land=cost of pipeline on land, H=some distance in water
a=0;b=L;xM = (a + b)/2;f(xM)= (C_ocean/sqrt(H^2+xM^2))-C_land;% derivative of function
while abs(f(xM))>1*10^(-6)% tolerance
if sign(f(a))==sign(f(xM)) a=xM; elseif sign(f(b))==sign(f(xM)) b=xM; end xM = (a + b)/2; endx=xM;end
Best Answer