<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: MATLAB Puzzler: Professor and the Rain</title>
	<atom:link href="http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/</link>
	<description>Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.</description>
	<lastBuildDate>Fri, 10 Feb 2012 20:31:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Babak Taati</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1437</link>
		<dc:creator>Babak Taati</dc:creator>
		<pubDate>Fri, 15 May 2009 14:18:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1437</guid>
		<description>that&#039;s pretty good Petter.</description>
		<content:encoded><![CDATA[<p>that&#8217;s pretty good Petter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yi Cao</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1398</link>
		<dc:creator>Yi Cao</dc:creator>
		<pubDate>Fri, 17 Apr 2009 13:49:41 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1398</guid>
		<description>&lt;pre&gt; &lt;code&gt;
function wetprob=puzzler(P,N)

% P - probability of rain
% N - number of simulated steps
% wetprob - Probability to get wet

s = 1;  % state represents number of umbrellas (0~2). Initially, one in office and one at home
R = rand(N,1)&lt;P;
nW = 0; % number of wet times
for k=1:N
    r = R(k);
    w = r &amp; ~s;         % if rain and no umbrella then wet
    s = 2 - s + r - w;  % next step, 2-s initial, r-w to carry 
    nW = nW + w;
end
wetprob = nW / N;
&lt;/code&gt; &lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre> <code>
function wetprob=puzzler(P,N)

% P - probability of rain
% N - number of simulated steps
% wetprob - Probability to get wet

s = 1;  % state represents number of umbrellas (0~2). Initially, one in office and one at home
R = rand(N,1)&lt;P;
nW = 0; % number of wet times
for k=1:N
    r = R(k);
    w = r &amp; ~s;         % if rain and no umbrella then wet
    s = 2 - s + r - w;  % next step, 2-s initial, r-w to carry
    nW = nW + w;
end
wetprob = nW / N;
</code> </pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: dhull</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1396</link>
		<dc:creator>dhull</dc:creator>
		<pubDate>Tue, 14 Apr 2009 13:11:04 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1396</guid>
		<description>João,

Wow,  that is lightning quick.  Much faster than what I came up with (video to be posted this week).  I think this is the perfect example of optimizing for speed.  You left your original code as reference and commentary and managed to come up with an obfuscated but equivalent and faster set of code.  In this case, the speed was worth the extra time and effort it takes to maintain the code.

Thanks for a great solution!
Doug</description>
		<content:encoded><![CDATA[<p>João,</p>
<p>Wow,  that is lightning quick.  Much faster than what I came up with (video to be posted this week).  I think this is the perfect example of optimizing for speed.  You left your original code as reference and commentary and managed to come up with an obfuscated but equivalent and faster set of code.  In this case, the speed was worth the extra time and effort it takes to maintain the code.</p>
<p>Thanks for a great solution!<br />
Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: João</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1395</link>
		<dc:creator>João</dc:creator>
		<pubDate>Mon, 13 Apr 2009 22:21:44 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1395</guid>
		<description>Here is my Monte Carlo like simulation.
&lt;pre&gt; &lt;code&gt;
function wetprob = puzzler

p = linspace(0.1,0.9,20); % prob. of rain
N = 1e6; % nr. of trips

wetcount = zeros(size(p)); % nr. of times the professor gets wet

for i = 1:numel(p)

    % initial state
    s = 1; % one umbrella available (can be 0, 1 or 2)
    w = 0; % nr. of times the professor gets wet

    q = p(i);
    for n = 1:N
        r = rand &lt; q; % rain?
        w = w + r*(0.5*(s-3)*s + 1);
        s = (1-r)*abs(s-2) + r*(0.5*(1-s)*s + 2);
        
        %%% equivalent switch ... case structure
        % switch r
        %     case 0
        %         switch s
        %             case 0, s = 2;
        %             %case 1, s = 1;
        %             case 2, s = 0;
        %         end
        %     case 1
        %         switch s
        %             case 0, s = 2; w = w + 1;
        %             case 1, s = 2;
        %             case 2, s = 1;
        %         end
        % end
    end
    
    wetcount(i) = w;
end

wetprob = wetcount/N; % simulated probability of getting wet
teoprob = (1-p).*p./(3-p); % theoretical probability of getting wet

plot(p, wetprob, &#039;b--o&#039;, p, teoprob, &#039;r-.&#039;)
xlabel(&#039;p&#039;)
&lt;/code&gt; &lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Here is my Monte Carlo like simulation.</p>
<pre> <code>
function wetprob = puzzler

p = linspace(0.1,0.9,20); % prob. of rain
N = 1e6; % nr. of trips

wetcount = zeros(size(p)); % nr. of times the professor gets wet

for i = 1:numel(p)

    % initial state
    s = 1; % one umbrella available (can be 0, 1 or 2)
    w = 0; % nr. of times the professor gets wet

    q = p(i);
    for n = 1:N
        r = rand &lt; q; % rain?
        w = w + r*(0.5*(s-3)*s + 1);
        s = (1-r)*abs(s-2) + r*(0.5*(1-s)*s + 2);

        %%% equivalent switch ... case structure
        % switch r
        %     case 0
        %         switch s
        %             case 0, s = 2;
        %             %case 1, s = 1;
        %             case 2, s = 0;
        %         end
        %     case 1
        %         switch s
        %             case 0, s = 2; w = w + 1;
        %             case 1, s = 2;
        %             case 2, s = 1;
        %         end
        % end
    end

    wetcount(i) = w;
end

wetprob = wetcount/N; % simulated probability of getting wet
teoprob = (1-p).*p./(3-p); % theoretical probability of getting wet

plot(p, wetprob, 'b--o', p, teoprob, 'r-.')
xlabel('p')
</code> </pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: dhull</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1394</link>
		<dc:creator>dhull</dc:creator>
		<pubDate>Mon, 13 Apr 2009 13:22:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1394</guid>
		<description>Everyone,

These are much better answers than I came up with.  I knew there was cleaner math than what I used.  Twenty minutes programming will save you two minutes in a library... :)

Later this week, I will post the Monte Carlo code optimization and a graph of the solution.

-Thanks,
Doug

PS, Tim- Pretty sure the professor wore polyester, most of mine did at least! :)</description>
		<content:encoded><![CDATA[<p>Everyone,</p>
<p>These are much better answers than I came up with.  I knew there was cleaner math than what I used.  Twenty minutes programming will save you two minutes in a library&#8230; :)</p>
<p>Later this week, I will post the Monte Carlo code optimization and a graph of the solution.</p>
<p>-Thanks,<br />
Doug</p>
<p>PS, Tim- Pretty sure the professor wore polyester, most of mine did at least! :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1393</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Sun, 12 Apr 2009 19:43:30 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1393</guid>
		<description>What&#039;s the rest of the story?  Don&#039;t leave us hanging here, with just the bare facts.

Is the professor upset at getting wet, and if so does he walk faster?  Does he wear jeans or polyester; the latter taking longer to dry and feels worse when he gets wet?  Is he bald or not?  (Since it&#039;s well know that a full head of hair increases the chance of rain, due to an increase static electricity discharged into the atmoshere).

Does the professor meet her true love at a rainy bus stop when a passerby offers her his own umbrella?  If so, what is the probability that they will have four children, two boys and two girls, as compared with a different gender mix of four children?  (Hint: assuming 4 children, the answer is not 50%).

Have to inked a contract for the book rights, and when will the DVD come out?

Inquiring MATLAB&#039;ers Want to Know...

;-)</description>
		<content:encoded><![CDATA[<p>What&#8217;s the rest of the story?  Don&#8217;t leave us hanging here, with just the bare facts.</p>
<p>Is the professor upset at getting wet, and if so does he walk faster?  Does he wear jeans or polyester; the latter taking longer to dry and feels worse when he gets wet?  Is he bald or not?  (Since it&#8217;s well know that a full head of hair increases the chance of rain, due to an increase static electricity discharged into the atmoshere).</p>
<p>Does the professor meet her true love at a rainy bus stop when a passerby offers her his own umbrella?  If so, what is the probability that they will have four children, two boys and two girls, as compared with a different gender mix of four children?  (Hint: assuming 4 children, the answer is not 50%).</p>
<p>Have to inked a contract for the book rights, and when will the DVD come out?</p>
<p>Inquiring MATLAB&#8217;ers Want to Know&#8230;</p>
<p>;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Woodford</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1392</link>
		<dc:creator>Oliver Woodford</dc:creator>
		<pubDate>Sat, 11 Apr 2009 12:47:02 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1392</guid>
		<description>OK, I got there in the end and also get p(1-p)/(3-p).

The way I did it was write an expression for q(0) as a function of p and q(2), and an expression for q(2) as a function of p and q(0), where q(x) is the probability of having x umbrellas (these expressions are both geometric series). I then substituted out q(2), giving an expression for q(0), which I then just multiply by p to give the answer. I wouldn&#039;t call it elegant :)</description>
		<content:encoded><![CDATA[<p>OK, I got there in the end and also get p(1-p)/(3-p).</p>
<p>The way I did it was write an expression for q(0) as a function of p and q(2), and an expression for q(2) as a function of p and q(0), where q(x) is the probability of having x umbrellas (these expressions are both geometric series). I then substituted out q(2), giving an expression for q(0), which I then just multiply by p to give the answer. I wouldn&#8217;t call it elegant :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Petter</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1391</link>
		<dc:creator>Petter</dc:creator>
		<pubDate>Sat, 11 Apr 2009 11:59:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1391</guid>
		<description>Maybe something like this, using the matrix from before:

&lt;pre&gt; &lt;code&gt;
syms p
A = [0 0 1;  %If the professor has no umbrella, he will for
             %sure end up with 2 at his destination
     0 1-p p; %If has has 1 umbrella, he will bring it 
              %with probability p
    1-p p 0]; %If he has 2 umbrellas, he will bring one
              %of them with prob. p
      
%Calculate eigenvectors of the transpose
[V E] = eig(A.&#039;)

%Find eigenvector with eigenval. 1
ind = find( diag(E) == 1 )
Sol =  V(:,ind).&#039;
%Normalize
Sol = Sol / (sum(Sol))

%Solution
Sol(1) * p
&lt;/code&gt; &lt;/pre&gt;

I get (1-p)/(3-p)*p  as the analytical formula.</description>
		<content:encoded><![CDATA[<p>Maybe something like this, using the matrix from before:</p>
<pre> <code>
syms p
A = [0 0 1;  %If the professor has no umbrella, he will for
             %sure end up with 2 at his destination
     0 1-p p; %If has has 1 umbrella, he will bring it
              %with probability p
    1-p p 0]; %If he has 2 umbrellas, he will bring one
              %of them with prob. p

%Calculate eigenvectors of the transpose
[V E] = eig(A.')

%Find eigenvector with eigenval. 1
ind = find( diag(E) == 1 )
Sol =  V(:,ind).'
%Normalize
Sol = Sol / (sum(Sol))

%Solution
Sol(1) * p
</code> </pre>
<p>I get (1-p)/(3-p)*p  as the analytical formula.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Petter</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1390</link>
		<dc:creator>Petter</dc:creator>
		<pubDate>Sat, 11 Apr 2009 11:43:28 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1390</guid>
		<description>There is an analytical solution. It is possible to analytically calculate the left eigenvector of the matrix A in my code.</description>
		<content:encoded><![CDATA[<p>There is an analytical solution. It is possible to analytically calculate the left eigenvector of the matrix A in my code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Woodford</title>
		<link>http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1389</link>
		<dc:creator>Oliver Woodford</dc:creator>
		<pubDate>Sat, 11 Apr 2009 11:37:42 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/04/10/matlab-puzzler-professor-and-the-rain/#comment-1389</guid>
		<description>Blast - I made a mistake in my analytical solution. I still think it is possible to evaluate, though. I may come back with a correction.

Nice solution, Petter.
Oliver</description>
		<content:encoded><![CDATA[<p>Blast &#8211; I made a mistake in my analytical solution. I still think it is possible to evaluate, though. I may come back with a correction.</p>
<p>Nice solution, Petter.<br />
Oliver</p>
]]></content:encoded>
	</item>
</channel>
</rss>

