Question
Here is a skeleton: https://dl.dropboxusercontent.com/u/43553083/biskel.m
Here is a hint:
Project: Bar Cooling We consider a bar of length L. We suppose its temperature is zero at one end and, at the other, is proportional to the outflux of heat there. The rate at which the bar dissipates heat is the square of the least, strictly positive solution, x, of sin(xL) + xcos (xL) =0 Our task is to determine how this root depends on L, the length of the bar. In particular, we will reproduce the figure below. We will accomplish this by composing 3 simple functions within a single m-file. The m-file (called cooldrive.m) will look like The decay rate is a decreasing function of bar length. function cooldrive % this is the driver % set a, t and a range of L and b and find x % and plot x^2 against L return function x = cool(a,b,t,L) % for a given a, b, t, and L find x % code bisection return function val = coolfun(x,L) % for a given x and L evaluate "cool" val = sin(x*L) + x*cos(x*L); return In cooldrive I would set a = 0.1 and b = 3 and t = 0.01 and compute the root x at each L = 1 : .1 : 4 and produces a figure like that above. I recommend accumulating the L and x values and issuing one plot command at the end of the loop. For example, for cnt = 1:31 L(cnt) = 1 + (cnt-l)/10; x(cnt) = cool(a,b,t,L(cnt)); end plot(L,x.^2) The trouble with this loop however is that Equation (l) may have more than one root between a = 0.1 and b = 3. I recommend that you move one or both of these as you change L. We suppose we have a Matlab function that evaluates f(x) when given x. We also suppose the user has provided us with an interval of interest, [a, b], and a tolerance t. Our job is to find an x in [a,b] for which |f(x)| 0 inform the user that a solution may not exist in [a,b] and exit. Set x = (a + b)/2. While |f(x)| > t do If f(a)f(x) > x=biskel(0,.5,1) Sorry, but I can not be sure your fun changes sign on [a,b] x = NaN >> biskel(0,1.5,1) x = 0.7500 I have left it for you to code steps 2 and 3. There are a number of ways to do it. I suggest a while loop that encloses an if clause.
Explanation / Answer
looks like u trying to access position (0) of the vector fun
i think our problem is that u think your fun is a function but its actually a vector...
i think(if i understand) u want something like this:
fun=@(x) x.^3-exp(-.5*x);
BisectionRoot(fun,0,1,.00001