Function Handle Assignment
This solution is perhaps a little bit fancier than it has to be, but illustrates what I want to show.
Problem 1: The Lambert W function
I wrote a function called myLambert, which is at the bottom of this file. Here is how it works:
fprintf('I calculated W(2)=%0.4f.\n',myLambert(2));
fprintf('MATLAB''s builtin lambertw function gives %0.4f.\n',lambertw(2))
Problem 2: Find all the zeros of
First, let's just define the function and plot it to see what it looks like
I see six zeros. I will find them by defining an array of x values. If , then there is a root on the interval .
Note that if the zero occurs at one of the endpoints, it will be double counted. Eliminate duplicates:
title('The zeros are between the $\circ$ and $\times$ marks')
fprintf('The zeros are:\n')
The implementation of the Lambert-W function
assert(xIn>-exp(-1),'xIn must be bigger than -1/e')