Technical Difficulties from on Top of the Mountain
2020-09-25
  Learning Maths
I decided that I needed to brush up on my math (probably from a glacing blow with Navier-Stokes equations while watching videos about airplane design), and I ran across some excellent lectures on Fourier transforms which I understood conceptually, but I had never learned how fast Fourier transforms were constructed. Now I know that the formula e=1 tells you everything you need to know, since you need n roots of 1.

But beyond that, I had a lot of fun with the explanations of Laplace transforms by Steve Brunton at the University of Washington:

After digging through all his published videos, I found he tought a series of graduate classes in Engineering Mathematics which for some reason is a Mechanical Engineering course, but I didn't let that stop me. I queued up the beginning of the series and got started.

The first two lectures were just review (even for me), and I breezed right through them. The third one was on Taylor series. Now I did Taylor series in college, and never gave them another thought, so it still felt a bit of a review; but then the professor jumped in to Matlab to do some calculations and graphing. I've seen Matlab before, heck I know people that use it, but its never looked fun, and more importantly its a commercial piece of software. Not that there's anything wrong with commercial software, heck that's what I do for a living, but I'm not going to go out and buy Matlab just because I'm watching some videos on the internet. The last time I bumped into this problem, I found there was an open-source version called scilab, but that was more than ten years ago which is forever in computer years. Time to brush up on what's available out there.

Asking the keeper of all knowledge for "matlab alternative free" (the free is both implied and auto-suggested), and it turns out the scilab is still kicking, but that GNU is trying to run it over with Octave. (You would think that open source people would get along better than commercial people, but you would be wrong. Apparently when you're no longer in it for the money, all that's left is honor and glory, and history has taught us that that never ends well.) There are also a couple of python based options, like NumPy and Sage which are wedded to Python grammer. And there's Julia, something nebulous thrown together by MIT.

The path of least resistance probably would have been the clones, as I could copy and paste the examples from the lectures and run them with minimal rework. But when I have bumped into Matlab before, its grammer has always seemed about as close to an actual programming language as PHP; and I just couldn't bring myself to do that. Something Python based would have been practical, since its a very popular dynamic language at work, and used by the ML groups; but I made the mistake of learning Perl earlier in my career, and if you ever read transition guides for perl to python, its a lot of putting the training wheels back on; plus the whitespace sensitive syntax can go wrong in horrible opaque ways (holds up hands to show the scars). So of course I chose Julia.

The example from the ME564 Lecture 3 video was to plot sin(x) and then plot the partial Taylor expansions of it to the 1st, 2nd, 3rd ... terms.

begin
	using Plots
	using TaylorSeries
	using Random
	
	x= -5π/4:.01:5π/4
	sin_ish2= Taylor1([0,1,0,-1//(3*2)])
	sin_ish3= Taylor1([0,1,0,-1//(3*2),0,1//(5*4*3*2)])
	sin_ish4= Taylor1([0,1,0,-1//(3*2),0,1//(5*4*3*2),0,-1//(7*6*5*4*3*2)])
	taylors= [ x-> x             ## taylor of sin 𝒪(t)
	           x-> sin_ish2( x ) ## taylor of sin 𝒪(t^3)
	           x-> sin_ish3( x ) ## taylor of sin 𝒪(t^5)
	           x-> sin_ish4( x ) ## taylor of sin 𝒪(t^7)
	         ]
	labels = [ "taylor1" "taylor2" "taylor3" "taylor4" ]
	
	pl_= plot( x, x-> sin(x), title= "approximations", label="sine", linewidth= 4)
	plot!( x, taylors, label= labels )
	plot!( x, x-> rand()/2-1/4, label= "noise" )
	
	savefig( pl_, "/tmp/julia_sin.pdf" )
	pl_
end
This is run in Pluto, which is a HTML notebook system, kind of like Jupyter; which makes pretty pictures as you go. There's some things I like so far, and things I don't. There's no compact operator for factorial, and since 7*6*5*4*3*2 is shorter than factorial(7), I just used that. I used rational representations for the fractions just on a whim, no good reason. And the ability to dump out a PDF as you go is kind of cool.

osmosis I threw in the noise there, just because I was cribbing off some examples of scatter plots of random values, and was trying to get an understanding of its use through osmosis. (random(3) is not a random value between 0 and 3, like it would be in other languages, but is a vector of three random numbers.)

There still seems to be overlap with Matlab syntax, so I'm partially doomed there. My biggest gripe is that I have to call the Taylor1 generator first, and then create a function out of its result (x -> sin_ish2(x)) in taylors as putting the generator call in the function, even if I could figure out how to dereference it, would have it be called for every plot point. There's probably a way, but I didn't get anywhere close to finding it groping through the various getting started examples. I'm probably doing a dis-service to Taylor1 as well, as I really can't tell the difference between that and Poly().

 
Comments: Post a Comment

<< Home
Life in the middle of nowhere, remote programming to try and support it, startups, children, and some tinkering when I get a chance.

ARCHIVES
January 2004 / February 2004 / March 2004 / April 2004 / May 2004 / June 2004 / July 2004 / August 2004 / September 2004 / October 2004 / November 2004 / December 2004 / January 2005 / February 2005 / March 2005 / April 2005 / May 2005 / June 2005 / July 2005 / August 2005 / September 2005 / October 2005 / November 2005 / December 2005 / January 2006 / February 2006 / March 2006 / April 2006 / May 2006 / June 2006 / July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / January 2007 / February 2007 / March 2007 / April 2007 / June 2007 / July 2007 / August 2007 / September 2007 / October 2007 / November 2007 / December 2007 / January 2008 / May 2008 / June 2008 / August 2008 / February 2009 / August 2009 / February 2010 / February 2011 / March 2011 / October 2011 / March 2012 / July 2013 / August 2013 / September 2013 / October 2013 / November 2013 / December 2013 / December 2014 / February 2015 / March 2015 / July 2016 / September 2016 / December 2016 / April 2017 / June 2017 / July 2018 / November 2018 / January 2019 / February 2019 / April 2019 / December 2019 / March 2020 / April 2020 / May 2020 / September 2020 / November 2020 / March 2021 / May 2023 / June 2024 /


Blogroll
Paul Graham's Essays
You may not want to write in Lisp, but his advise on software, life and business is always worth listening to.
How to save the world
Dave Pollard working on changing the world .. one partially baked idea at a time.
SnowDeal
Eric Snowdeal IV - born 15 weeks too soon, now living a normal baby life.
Land and Hold Short
The life of a pilot.

The best of?
Jan '04
The second best villain of all times.

Feb '04
Oops I dropped by satellite.
New Jets create excitement in the air.
The audience is not listening.

Mar '04
Neat chemicals you don't want to mess with.
The Lack of Practise Effect

Apr '04
Scramjets take to the air
Doing dangerous things in the fire.
The Real Way to get a job

May '04
Checking out cool tools (with the kids)
A master geek (Ink Tank flashback)
How to play with your kids

Powered by Blogger