Post Tagged math

Newton’s Method .to_ruby

Sunday, 03 March 2009

here is the math behind Newton’s Method

PRECISION = 0.0001
 
def newtonian_guess( guess,fx,fdx )
  loop do
    better_guess = guess - ( fx.call( guess ).to_f / fdx.call( guess ).to_f )
    return better_guess if ((better_guess - guess).abs <= PRECISION)
    guess = better_guess
  end
end
 
def sqrt( num )
  guess = num/2
  return newtonian_guess( guess,
            lambda {|x| (x**2)-num } ,
            lambda {|x| 2*x } )
end
 
class Float
  def to_sqrt
    sqrt( self )
  end
end
 
p 2.0.to_sqrt
# => 1.41421356237469

oh the glory

Sunday, 02 February 2009

Just as i transformed a matrix into reduced echelon form, i became inundated with loud cheering and screaming. There was a great celebration. It seems that the Party Goers in my building have installed a spy camera in my loft. They are all in the commons area huddled around the television as they watch me solve math problems.


Improved Euler Method in Mathematica.

Tuesday, 09 September 2008

So let us take a look at the case where we need to obtain a numerical approximation to a ODE. Just go to wikipedia to find some theory of when and why this works…..i will show you the algorithm implemented in Mathematica.  The general solution looks like this:

k_1 = f(x_n,y_n)
k_2 = f(x_n + h, y_n + h \ast k_1)
k = \frac{1}{2} (k_1 + k_2)
y_{n+1} = y_n +hk
x_{n+1} = x_n + h

consider the differential equation:
\dot{y} = y^2 : y(0)=1 \: and \: h =.2
Mathematica Code:

Clear[x, y, x0, y0, h, n, k, k1, k2, tbl]
 
f[x_, y_] = y^2;
 
{x, y, h} = {0, 1, .2};
 
tbl = {{x, y}};
 
n = 6;
Do[
k1 = f[x, y];
k2 = f[x + h, y + h*k1];
k = (k1 + k2)/2;
y = y + h*k;
x = x + h;
AppendTo[tbl, {x, y}]
, {i, 1, n}]

So, your Mathematica notebook should look something like this.

While you are at it, you might as well plot the data:


Plotting Slope Fields and Isoclines with Mathematica

Tuesday, 09 September 2008

I have yet to meet a human who enjoys plotting vector fields. However, my computer loves them. With a super swell package from http://www.appliedsymbols.com/ you can teach your machine to plot slope fields.

Now, without stating or proving the Picard–Lindelöf theorem (these guys showed that for an initial value problem there exists a unique solution) we will take a look at a solution of an Ordinary Differential Equation via it’s slope fields.

consider:
 dot{y} = frac{y+t}{y-t}

This seems like a tricky ODE. However we can observe some of it’s strange behavior by plotting the slopes at different points in the chosen interval. This is how we do it in mathematica.

So go grab the DE package for mathematica and play around. We will come back to this interesting equation later…….


Learning Math

Friday, 07 July 2008

\rho = learning
\frac{\partial \rho}{\partial t} = slow

This is not an easy one. As a matter of fact, i am still trying to figure this one out. However, i have made one shocking discovery; you can not just read a math book. To understand the idea that the author is trying to convey, you must pull out some paper and a pencil and work through problem sets. I have found a wonderful site full of example problems.
http://www.exampleproblems.com/

Also, check out this article. http://www.stonehill.edu/compsci/History_Math/math-read.htm
Shai Simonson is one of my favorite mathematicians, he gives great insight into the art of reading mathematics.
Good luck!