Mars is a cold and barren desert today, but scientists think that in the ancient past it was warm and wet. The loss of the early Martian atmosphere may have led to this dramatic change, and one of the prime suspects is the solar wind. Unlike Earth, Mars lacks a global magnetic field to deflect the stream of charged particles continuously blowing off the Sun. Instead, the solar wind crashes into the Mars upper atmosphere and can accelerate ions into space. Now, for the first time, NASA’s MAVEN spacecraft has observed this process in action – by measuring the speed and direction of ions escaping from Mars. This data visualization compares simulations of the solar wind and Mars atmospheric escape with new measurements taken by MAVEN.

Consider you want to define a function in Matlab, plot it, and differentiate it. This can be done in two ways. Let’s demonstrate the two methods on the function

whose derivative is

The first is using function handles (ie; numerically) that take & return values as input & output. Function handles require the inputs to be initialized. Here’s an example:

x = linspace(0.5, 5.0)'; % range of x as column vector
f = x - 3 * log(x); % returns numerical values
df = diff(f) ./ diff(x); % also numerical values of the derivative

The other is symbolically (ie; like you do in your math class) as such

syms x % define symbolic variables
f = x - 3 * log(x); % symbolic function
df = diff(f, x); % gives the symbolic derivative

which returns

f = x - 3*log(x)
df = 1 - 3/x

But this way you cannot give the funtion numerical inputs and hence can’t plot it. To do so you’ll have to convert the function to a function handle which is easy using matlabFunction():

f_handle = matlabFunction(f); % convert symbolic fn to a handle
f_handle(2); % value of f @ x = 2
x = linspace(0.5, 5.0)'; % define range for x as column vector
plot(x, f_handle(x) ) % plot f on the range x

I reproduce here below principles from the amazing paper Best Practices for Scientific Computing, published on 2012 by a group of US and UK professors. The main purpose of the paper is to “teach” good programming habits shared from professional developers to people that weren’t born developer, and became developers just for professional purposes.

Scientists spend an increasing amount of time building and using software. However, most scientists are never taught how to do this efficiently

Best Practices for Scientific Computing

Write programs for people, not computers.

a program should not require its readers to hold more than a handful of facts in memory at once

names should be consistent, distinctive and meaningful

code style and formatting should be consistent

all aspects of software development should be broken down into tasks roughly an hour long

“We call it the Wolfram Language because it is a language. But it’s a new and different kind of language. It’s a general-purpose knowledge-based language. That covers all forms of computing, in a new way.
There are plenty of existing general-purpose computer languages. But their vision is very different—and in a sense much more modest—than the Wolfram Language. They concentrate on managing the structure of programs, keeping the language itself small in scope, and relying on a web of external libraries for additional functionality. In the Wolfram Language my concept from the very beginning has been to create a single tightly integrated system in which as much as possible is included right in the language itself.”

This is what Wolfram himself mentions in his blog post last November “Something Very Big is Coming: Our Most Important Technology Project Yet” [1] as an introduction to another blog post which appeared on November 21 “Putting the Wolfram Language (and Mathematica) on Every Raspberry Pi” in which he publicizes his plans and futuristic but old views for Mathematica and the Wolfram language [WL].

The projects that Wolfram uncovered are:

Mathematica and Wolfram language on the Raspberry Pi [2]

Mathematica Online [3]

Wolfram Cloud [4]

Even though many would argue against this vision of a language that does not rely on external libraries or modules, including my self, given that libraries is a way to reuse code by other programs, which in the case of the WL is not the way to go given that it is mostly a commercial software, I think that what Wolfram is attempting is the way to further increase the value and power of the WL and Mathematica as indicated in this quote:

“Seeing how incredibly powerful it is to be able to treat code like data, interspersing little programs inside a piece of graphics, or a document, or an array of data. Or being able to put an image, or a user interface element, directly into the code of a program. Or having any fragment of any program immediately be runnable and meaningful.”

“In most languages there’s a sharp distinction between [algorithms and data]. Not so in the Wolfram Language… Data becomes algorithmic. Algorithms become data.”

I truly appreciate this thought that algorithms and data could be similarly dealt with. This is the first step towards a very powerful language that is, I think, capable of being used for artificial intelligence on a large scale.

What Wolfram publicized in these blog posts further supports my belief in this computer algebra system [CAS]. Moreover I see the WolframAlpha knowledge-based engine [5] as the first draft, which lacks (to my knowledge) the ability to display web results like other engines, of a full-blown search engine that will replace many of the current ones.
Further, introducing a free version of Mathematica and WL bundled within the Raspberry Pi will serve well both the Raspberry Pi users and Wolfram [6] it self.

Moreover, Wolfram intends to connect everything you can imagine to the internet [7] and this is why Wolfram started the “Wolfram Connected Devices Project” [8].

This post was written a few weeks before the following video was posted in which Stephen Wolfram talks about the WL. I leave you with this video.

Graph of the probability distribution of the 100th state of the quantum
harmonic oscillator (generated using the power series method).

and stated that I might write a post on how to solve the Quantum harmonic oscillator numerically using the power series method (the other method being the ladder operator method [1]) and generate that figure. This post is just about that.

Ok. First I need to clear the cache with the restart command, import the PDEtools (to solve the pde SE) and Maplets[Elements] (necessary if you want to generate a maplet with a slider) packages.

restart;
with(PDEtools): #we need to use the dchange command later in the solution
with(Maplets[Elements]):