Question
Here is a skeleton: https://dl.dropboxusercontent.com/u/43553083/biskel.m
Here is a hint:
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 heal IIUTC The rate at which the bar dissipates heat is the square of the least, strictly positive solution, x, of sin(xL) + xcos(xL) = 0 (1) 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 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 (1) 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 + 6)/2. While |f(x)| > t do If f(a)f(x)
Explanation / Answer
%function for bisection
%assuming function polynomial or handler is already in workspace
function [x]=bisect(a,b,tol)
if f(a)*f(b) >0
disp('no solution exists');
exit(1);
end
x=a;
while(f(x)> tol)
x=(a+b)/2;
if f(x)*f(a) <0
x=b;
else x=a;
end
end
end