text:
Available software

### Software of the lab computers

The lab computers are intended to have a basic set of mathematical, web and office software to enable you to carry out most tasks.

This is one of the best programs for working with graphic images. It is able to import images from the scanner. It is only on the Apple PowerMac G5. See http://www.adobe.com/products/

#### Maple

This is a general-purpose program that can be used for most mathematical work. In many cases there is a choice between doing mathematics either symbolically (exact) or numerically. Maple is also programmable. Disadvantages: Text-based input for mathematical notation. It is not very good at doing some calculus problems. You need a good memory to use it efficiently. Advantages: Very comprehensive, good help and nice graphics (3D graphs can be rotated using the mouse). See http://www.mathsoft.com/

General-purpose software used for computations and graphics with an Engineering orientation. It is fast, has many built in functions which can be entered anywhere on the screen. It includes access to a number of reference books on Physics and other fields and a design tool Imagine Engineer. Disadvantages: weak programming ability. Advantages: Nice recalculation feature: when you change some data. Better at calculus than Maple. See http://www.mathsoft.com/

MATLAB: (Various versions: 5.3, 6.1, student version): the premier computation and mathematical graphics software with excellent programming ability. Disadvantage: Command line orientation similar to DOS and a text-based input for mathematical notation. Advantages: Very fast, accurate and easily programmable. The versions 5.3 and 6.1 have a Matlab code to C/C++ code converter. See http://www.mathworks.com/

#### SCIENTIFIC WORKPLACE

(Versions 3.0 or 3.5), or Scientific Notebook 3.5. A WYSIWYG program with accurate on-screen mathematical notation, publication quality Latex output good for theses and journal publications. It has the Maple kernel enabling mathematical statement to be evaluated. Disadvantages: No programming and some Maple functions cannot be used. Advantages: All Mathematical Symbols can be entered directly without difficult-to-use text based input, publication quality output, live mathematical expressions, easy style changes. See: http://www.mackichan.com/

#### MICROSOFT OFFICE

Generally the professional version includes WORD (word processor), EXCEL (spread sheet), ACCESS (Data base manager), POWERPOINT (Presentation software good for seminars), FRONTPAGE (Web page design) and OUTLOOK (Personal information manager and E-mail program). N.B. E-mail is hard to use on the lab computers unless you have a web-based E-mail address. See: http://www.microsoft.com/

WEB BROWSERS: Netscape 4.7 and Internet Explorer 5 or 5.5.

#### Tools

4 or 5 (for reading .pdf documents), Winzip 8 (compressing and uncompressing files), WSFTP 5 (file transfer program for moving files to/from any computer running an FTP server), Telnet (opens a text-based terminal window on any computer running a telnet server, allowing logons to that computer and enabling non-graphical programs to be run off that computer) and Command Antivirus. The lab will soon have two copies of the award winning Macromedia web site creation software packages: Dreamweaver, Flash and Fireworks.

### Software available for use on staff and student computers

The University has available a large amount of free and low-priced software available for use on staff and student office computers and home computers. A major source for this is the Software Xpress site that has available a huge amount of software (web browsers, web design, FTP, Telnet, mail programs, Adobe Acrobat, imaging software, file compression/extraction and much more). Most of this software is free, but some of these programs do require a payment to activate them, such as \$75 each for the very powerful Macromedia Dreamweaver, Flash and Fireworks web design programs. Many of these programs are on the UMConnect CD that is sold at the bookstore at a very low price;

Other site-licensed software programs available include Maple, Mathcad, Autocad, SAS, SPSS and much more. Some of these require a small payment and/or are only available to staff members. Some particularly interesting and little known ones are ZoomText, a windows text enlarger and speech program, and X-Win32, that enables X-windows to run on a Windows computer enabling multiple windows showing text and graphical output from Unix programs running on University Unix servers.

Computers on Campus, part of the University Bookstore, sells or can obtain a large amount of software at low educational prices. This includes education licenses for Microsoft Office. Educational and non-educationally software prices at Computers on Campus are often lower than can be obtained by purchasing anywhere else. This is especially true for software from the USA even when that software is downloaded over the Internet.

### News

In an effort to help students, the Math department has put together the LevelUp program. See details here. Video explaining registration process is here.

### Events

Tuesday, September 26th, 2017 at 14:40, 418 Machray Hall
Circle-realizable $(n_4)$-configurations
(Seminar series : Rings and Modules)

Tuesday, September 26th, 2017 at 15:00, 205 Armes Building
Ievgen Bilokopytov
Continuity and Holomorphicity of Symbols of Weighted Composition Operators
(Seminar series : Functional Analysis)

Monday, October 2nd, 2017 at 15:00, 415 Machray Hall
Kristin Courtney
TBA
(Seminar series : Functional Analysis)

Friday, November 3rd, 2017 at 08:00, TBA
Steve Reinhardt
TBA
(Seminar series : Colloquium)

format: plain


text:
Wednesday, September 16, 2015

Nerd Food: Neurons for Computer Geeks - Part VI: LIF At Long Last!

Nerd Food: Neurons for Computer Geeks - Part VI: Integrate and Fire!

Welcome to part VI of a multi-part series on modeling neurons. In part V we added a tad more theory to link electricity with neurons, and also tried to give an idea of just how complex neurons are. Looking back on that post, I cannot help but notice I skipped one bit that is rather important to understanding Integrate-and-Fire (IAF) models. So lets look at that first and then return to our trail.

Resting Potential and Action Potential

We have spoken before about the membrane potential and the resting membrane potential, but we did so with such a high degree of hand-waving it now warrants revisiting. When we are talking about the resting membrane potential we mean just that - the value for the membrane potential when nothing much is happening. That is the magical circa -65mv we discussed before - with all of the related explanations on conventions around negative voltages. However, time does not stand still and things happen. The cell receives input from other neurons, and this varies over time. Some kinds of inputs can cause events to trigger on the receiving neuron: active ion channels may get opened or shut, ions move around, concentrations change and so forth, and thus, the cell will change its membrane potential in response. When these changes result in a higher voltage - such as moving to -60mv - we say a depolarisation is taking place. Conversely, when the voltage becomes more negative, we say hyperpolarisation is occurring.

Now, it may just happen that there is a short-lived but "strong" burst of depolarisation, followed by equally rapid hyperpolarisation - and, as a result of which, the Axon's terminal decides to release neurotransmitters into the synapse (well, into the synaptic gap or synaptic cleft to be precise). This is called an action potential, and it is also known by many other names such as "nerve impulses" or "spikes". When you hear that "a neuron has fired" this means that an action potential has just been emitted. If you record the neuron's behaviour over time you will see a spike train - a plot of the voltage over time, clearly showing the spikes. Taking a fairly random example:

One way of picturing this is as a kind of "chain-reaction" whereby something triggers the voltage of the neuron to rise, which triggers a number of gates to open, which then trigger the voltage to rise and so on, until some kind of magic voltage threshold is reached where the inverse occurs: the gates that were causing the voltage to rise shut and some other gates that cause the voltage to decrease open, and so on, until we fall back down to the resting membrane potential. The process feeds back on itself, first as a positive feedback and then as a negative feedback. In the case of the picture above, something else triggers us again and again, until we finally come to rest.

This spiking or firing behaviour is what we are trying to model.

Historical Background

As it happens, we are not the first ones to try to do so. A couple of years after Einstein's annus mirabilis, a french chap called Louis Lapicque was also going through his own personal moment of inspiration, the output of which was the seminal Recherches quantitatives sur l'excitation électrique des nerfs traitée comme une polarisation. It is summarised here in fairly accessible English by Abbot.

Lapicque had the insight of imagining the neuron as an RC circuit, with the membrane potential's behaviour explained as the interplay between capacitor and resistor; the action potential is then the capacitor reaching a threshold followed by a discharge. Even with our faint understanding of the subject matter, one cannot but appreciate Lapique's brilliance to have the ability to reach these conclusions in 1907. Of course, he also had to rely on the work of many others to get there, let's not forget.

This model is still considered a useful model today, even though we know so much more about neurons now - a great example of what we mentioned before in terms of the choices of the level of detail when modeling. Each model is designed for a specific purpose and it should be as simple as possible for the stated end (but no simpler). As Abbot says:

While Lapicque, because of the limited knowledge of his time, had no choice but to model the action potential in a simple manner, the stereotypical character of action potentials allows us, even today, to use the same approximation to avoid computation of the voltage trajectory during an action potential. This allows us to focus both intellectual and computation resources on the issues likely to be most relevant in neural computation, without expending time and energy on modeling a phenomenon, the generation of action potentials, that is already well understood.

The IAF Family

Integrate-and-Fire is actually a family of models - related because all of them follow Lapicque's original insights. Over time, people have addressed shortcomings in the model by adding more parameters and modifying it slightly and from this other models were born.

In general, models in the IAF family are single neuron models with a number of important properties (as per Izhikevich):

• The spikes are all or none; that is, we either spike or we don't. This is a byproduct of the way spikes are added to the model, as we shall see later. This also means all spikes are identical because the are all created the same way.
• The threshold for the spike is well defined and there is no ambiguity as to whether the neuron will fire or not.
• It is possible to add a refractory period, similarly to how we add the spike. The refractory period is a time during which the neuron is less excitable (e.g. ignores inputs) and occurs right after the spike.
• Positive currents are used as excitatory inputs and negative currents as inhibitory inputs.

But how do the members of this family look like? We will take a few examples from Wikipedia to make a family portrait and then focus on LIF.

IAF: Integrate-and-Fire

This the Lapicque model. It is also called a "perfect" or "non-leaky" neuron. The formula is as follows:

\begin{align} I(t) = C_m \frac{dV_m(t)}{dt} \end{align}

The m's are there to signify membrane, nothing else. Note that its the job of the user to determine θ - that is the point at which the neuron spikes - and then to reset everything to zero and start again. If you are wondering why it's called "integrate", that's because the differential equation must be integrated before we can compare the current value to a threshold and then, if we're passed it, well - fire!. Hence Integrate-and-Fire.

Wikipedia states this in a classier way, of course:

[This formula] is just the time derivative of the law of capacitance, Q = CV. When an input current is applied, the membrane voltage increases with time until it reaches a constant threshold Vth, at which point a delta function spike occurs and the voltage is reset to its resting potential, after which the model continues to run. The firing frequency of the model thus increases linearly without bound as input current increases.

Integrate-and-Fire with Refractory Period

It is possible to extend IAF to take the refractory period into account. This is done by adding a period of time t ref during which the neuron does not fire.

LIF: Leaky Integrate-and-Fire

One of the problems of IAF is that it will "remember" stimulus, regardless of the time that elapses between stimuli. By way of example: if a neuron gets some input below the firing threshold at some time (say ta), then nothing for a long period of time and then subsequent stimulus at say tb, this will cause the neuron to fire (assuming the two inputs together are above the threshold). In the real world, neurons "forget" about below-threshold stimulus after certain amount of time has elapsed. This problem is solved in LIF by adding a leak term to IAF. The Wikipedia's formula is like so:

\begin{align} I_m(t) - \frac{V_m(t)}{R_m} = C_m \frac{dV_m(t)}{dt} \end{align}

We will discuss it in detail later on.

Interlude: Leaky Integrators and Low-Pass Filters

Update: this section got moved here from an earlier post.

Minor detour into the world of "Leaky Integrators". As it turns out, mathematicians even have a name to describe functions like the one above: they are called Leaky Integrators. A leaky integrator is something that takes an input and "integrates" - that is, sums it over a range - but by doing so, starts "leaking" values out. In order words, a regular sum of values over a range should just result in an ever growing output. With a leaky integrator, we add up to a point, but then we start leaking, resetting the value of the sum back to where we started off.

It turns out these kind of functions have great utility. For example, imagine that you have a range of inputs varying from some arbitrary low number to some other arbitrary high-number. When you supply these inputs to a leaky integrator, it can be used to "filter out" the high numbers; input numbers higher than a certain cut-off point just result in zeros in the output. This is known as a low-pass filter. One can conceive of a function that acted in the opposite way - a high-pass filter.

Exponential Integrate-and-Fire

In this model, spike generation is exponential:

\begin{align} \frac{dX}{dt} = \Delta_\tau exp(\frac{X - X_t}{\Delta_\tau}) \end{align}

Wikipedia explains it as follows:

where X is the membrane potential, XT is the membrane potential threshold, and ΔT is the sharpness of action potential initiation, usually around 1 mV for cortical pyramidal neurons. Once the membrane potential crosses XT, it diverges to infinity in finite time.

Others

We could continue and look into other IAF models, but you get the point. Each model has limitations, and as people work through those limitations - e.g. try to make the spike trains generated by the model closer to those observed in reality - they make changes to the model and create new members of the IAF family.

Explaining the LIF Formula

Let's look at a slightly more familiar formulation of LIF:

\begin{align} \tau_m \frac{dv}{dt} = -v(t) + RI(t) \end{align}

By now this should make vague sense, but lets do it step by step breakdown just to make sure we are all on the same page. First, we know that the current of the RC circuit is defined like so:

\begin{align} I(t) = I_R + I_C \end{align}

From Ohm's Law we also know that:

\begin{align} I_R = \frac {v}{R} \end{align}

And from the rigmarole of the capacitor we also know that:

\begin{align} I_C = C \frac{dv}{dt} \end{align}

Thus its not much of a leap to say:

\begin{align} I(t) = \frac {v(t)}{R} + C \frac{dv}{dt} \end{align}

Now, if we now multiply both sides by R, we get:

\begin{align} RI(t) = v(t) + RC \frac{dv}{dt} \end{align}

Remember that RC is τ, the RC time constant; in this case, we are dealing with the membrane so hence the m. With that, the rest of the rearranging to the original formula should be fairly obvious.

Also, if you recall, we mentioned Leaky Integrators before. You should hopefully be able to see the resemblance between these and our first formula.

Note that we did not model spikes explicitly with this formula. However, when it comes to implementing it, all that is required is to look for a threshold value for the membrane potential - called the spiking threshold; when that value is reached, we need to reset the membrane potential back to a lower value - the reset potential.

And with that we have enough to start thinking about code…

.. Or so you may think. First, a quick detour on discretisation. As it happens, computers are rather fond of discrete things rather than the continuous entities that inhabit the world of calculus. Computers are very much of the same opinion as the priest who said:

And what are these same evanescent Increments? They are neither finite Quantities nor Quantities infinitely small, nor yet nothing. May we not call them the Ghosts of departed Quantities?

So we cannot directly represent differential equations in the computer - not even the simpler ordinary differential equations (ODEs), with their single independent variable. Instead, we need to approximate them with a method for numerical integration of the ODE. Remember: when we say integration we just mean "summing".

Once we enter the world of methods and numerical analysis we are much closer to our ancestral home of Software Engineering. The job of numerical analysis is to look for ways in which one can make discrete approximations of the problems in mathematical analysis - like, say, calculus. The little recipes they come up with are called numerical methods. A method is nothing more than an algorithm, a set of steps used iteratively. One such method is the Euler Method: "[a] numerical procedure for solving ordinary differential equations (ODEs) with a given initial value", as Wikipedia tells us, and as it happens that is exactly what we are trying to do.

So how does the Euler method work? Very simply. First you know that:

\begin{align} y(t_0) = y_0 \\ y'(t) = f(t, y(t)) \end{align}

That is, at the beginning of time we have a known value. Then, for all other t's, we use the current value in f in order to be able to compute the next value. Lets imagine that our steps - how much we are moving forwards by - are of a size h. You can then say:

\begin{align} t_{n+1} = t_n + h \\ y_{n+1} = y_n + h * f(x_n, t_n) \end{align}

And that's it. You just need to know where you are right now, by how much you need to scale the function - e.g. the step size - and then apply the function to the current values of x and t.

In code:

template<typename F>
void euler(F f, double y0, double start, double end, double h) {
double y = y0;
for (auto t(start); t < end; t += h) {
y += h * f(t, y, h);
}
}

We are passing h to the function F because it needs to know about the step size, but other than that it should be a pretty clean mapping from the maths above.

This method is also known as Forward Euler or Explicit Euler.

What next?

And yet again, we run out of time yet again before we can get into serious coding. In the next instalment we shall cover the implementation of the LIF model.

Created: 2015-09-16 Wed 18:05

Emacs 24.5.1 (Org mode 8.2.10)

Validate

Monday, September 07, 2015

Nerd Food: Neurons for Computer Geeks - Part V: Yet More Theory

Nerd Food: Neurons for Computer Geeks - Part V: Yet More Theory

Welcome to part V of a multi-part series on modeling neurons. In part IV we introduced the RC Circuit by making use of the foundations we painstakingly laid in previous posts. In truth, we could now move on to code and start looking at the Leaky Integrate-and-Fire (LIF) model, since we've already covered most required concepts. However, we are going to do just a little bit more theory before we get to that.

The main reason for this detour is that I do not want to give you the impression neurons are easy; if there is one thing that they are not is easy. So we're going to resume our morphological and electrical exploits to try to provide a better account of the complexity inside the neuron, hopefully supplying enough context to appreciate the simplifications done in LIF.

The content of this post is highly inspired from Principles of Computational Modelling in Neuroscience, a book that is a must read introduction if you decide to become serious on this subject. If so, you may also want to check the Gerstner videos: Neural networks and biological modeling.

But you need not worry, casual reader. Our feet are firmly set in layman's land and we'll remain so until the end of the series.

Brief Context on Modeling

Before we get into the subject matter proper, I'd like us to ponder a few "meta-questions" in terms of modeling.

Why Model?

A layperson may think that we model neurons because we want to build a "computer brain": one that is similar to a real brain, with its amazing ability to learn, and one which at some point may even think and be conscious. Hopefully, after you finish this series of posts, you will appreciate the difficulty of the problem and see that it's not very likely we'll be able to make a "realistic" "computer brain" any time soon - for sensible values of "realistic", "computer brain" and "any time soon".

Whilst we have good models that explain part of the behaviour of the neuron and good models for neural networks too, it is not the case that we can put all of these together to form some kind of "unified neuron model", multiply it by 80 billion, add a few quadrillion synapses and away we go: artificial consciousness. Given what we know at the moment, this approach is far too computationally demanding to be feasible. Things would change if there was a massive leap in computational power, of course, but not if they stay at present projections - even with Moore's Law.

So if we are not just trying to build a computer brain, then why bother? Well, if you set your sights a little lower, computational models are actually amazingly useful:

• one can use code to explore a small portion of the problem domain, making and validating predictions using computer models, and then test those predictions in the lab with real wetware. The iterative process is orders of magnitude faster.
• computer models are now becoming quite sophisticated, so in some cases they are good representations of biological processes. This tends to be the case for small things such as individual cells or smaller. As computers get faster and faster according to Moore's Law, the power and scope of these models grows too.
• distributing work with Free and Open Source Software licences means it is much easier for researchers to reproduce each others work, as well as for them to explore avenues not taken by those who did the work originally, speeding things up considerably. Standing on the shoulders of giants and all that.

What Tools Do We Model With?

The focus of these posts is on writing models from scratch, but that's not how most research is conducted. In the real world, people try their best to reuse existing infrastructure - of which there is plenty. For example there is NEURON, PyNN, Brian and much more. Tools and processes have evolved around these ecosystems, and there is a push to try to standardise around the more successful frameworks.

There is also a push to find some kind of standard "language" to describe models so that we can all share information freely without having to learn the particulars of each others representations. The world is not quite there yet, but initiatives such as NeuroML are making inroads in this direction.

However, the purpose of our this series is simplification, so we will swerve around all of this. Perhaps material for another series.

At What Level Should One Model?

A related question to the previous ones - and one that is not normally raised in traditional software engineering, but is very relevant in biology - is the level of detail at which one should model.

Software Engineers tend to believe there is a model for a problem, and once you understand enough about the problem domain you will come up with it and all will be light. Agile and sprints are just a way to converge to it, to the perfection that exists somewhere in the platonic cloud. Eric Evans with DDD started to challenge that assumption somewhat by making us reflect on just what it is that we mean by "model" and "modeling", but, in general, we have such an ingrained belief in this idea that is very hard to shake it off or to even realise the belief is there in the first place. Most of us still think of the code representation of the domain model as the model - rather than accept it is one of a multitude of possible representations, each suitable for a given purpose.

Alas, all of this becomes incredibly obvious when you are faced with a problem like modeling a neuron or a network of neurons. Here, there is just no such thing as the "right model"; only a set of models at a different perspectives, each with a different set of trade-offs, and any of them only make sense in the context of what one is trying to study. It may make sense to model neurons like networks, ignoring the finer details of each one and looking at their behaviour as a group, or it may make sense to model individual bits of the neuron as an entity. What makes it "right" or "wrong" is what it is that we are using the model for and how much computational power one has at one's disposal.

Having said all of that, lets resume our morphology adventures.

Electricity and Neurons

We started off with an overview of the neuron and then moved over to lots and lots of electricity; now it's time to see how those two fit together.

As we explained in part I, there is a electric potential difference between the inside of the cell and the outside, called the membrane potential. The convention to compute this potential is to subtract the potential inside the cell to the potential outside the cell; current is positive when there is a flow of positive charge from the inside to the outside and negative otherwise. Taken into account these definitions, one should be able to make sense of the resting membrane potential: it is around -65mv. But how does this potential change?

Ion Channels

Earlier, we spoke about ions - atoms that either lost or gained electrons and so are positively or negatively charged. We also said that, in general, the cell's membrane is impermeable, but there are tiny gaps in the membrane which allow things in and out of the cell. Now we can expand a bit further. Ion channels are one such gap, and they have that name because they let ions through. There are many kinds of ion channels. One way of naming them is to use the ion they are most permeable to - but of course, this being biology, the ion channels don't necessarily always have a major ion they are permeable to.

Another useful categorisation distinguishes between passive and active ion channels. Active channels are those that change their permeability depending on external factors such as the membrane potential, the concentration of certain ions, and so on. For certain values they are open - i.e. permeable - whereas for other values they are closed, not allowing any ions through. Passive channels are simpler, they just have a fixed permeability behaviour.

There are also ionic pumps. These are called pumps because they take one kind of ion out, exchanging it for another kind. For instance, the sodium-potassium pump pushes potassium into the cell and expels sodium out. A pump has a stoichiometry, which is a fancy word to describe the ratio of ions being pumped in and out.

Complexity Starts To Emerge

As you can imagine, the key to understating electric behaviour is understanding how these pesky ions move around. Very simplistically, ions tend to move for two reasons: because there is a potential difference between the inside and the outside of the cell, or because of the concentration gradient of said ion. The concentration gradient just means that, left to their own devices, concentration becomes uniform over time. For example, if you drop some ink in a glass of water, you will start by seeing the ink quite clearly; given enough time, the ink will diffuse in the water, making it all uniformly coloured. The same principle applies to ions - they want to be uniformly concentrated.

It should be fairly straightforward to work out that a phenomenal number of permutations is possible here. Not only do we have a great number of channels, all with different properties - some switching on and off as properties change around the cell - but we also have the natural flow of ions being affected by the membrane's potential and the concentration gradient, all of which are changing over time. To make matters worse, factors interact with each other such that even if you have simple models to explain each aspect individually, the overall behaviour is still incredibly complex.

Now imagine more than 50 thousand such ion channels - of over one hundred (known) types - in just a single neuron and you are starting to get an idea of the magnitude of the task.

Equivalent Circuit for a Patch of Membrane

But lets return to simplicity. The very clever people determined that it is possible to model the behaviour of ions and its electric effects by thinking of it as an electric circuit. Taking a patch of membrane as an example, it can be visualised as an electric circuit like so:

What this diagram tells us is that the membrane itself acts as a capacitor, with its capacitance determined by the properties of the lipid bilayer. We didn't really discuss the lipid bilayer before so perhaps a short introduction is in order. The membrane is made up of two sheets of lipids (think fatty acids), which when layered so, have interesting properties: the outside of the sheets are impermeable to most things such as water molecules and ions. The membrane itself is pretty thin, at around 5nm.

The membrane capacitance is considered constant. We then have a series of ion channels: sodium, potassium, chlorine, calcium. Each of these can be thought of as a pairing of a resistor with variable conductance coupled with a battery. Note that the resistor and the battery are in series, but the ion channels themselves form a parallel circuit. The voltages for each pathway are determined by the different concentrations of the ion inside and outside the cell.

If we further assume fixed ion concentrations and passive ion channels, we can perform an additional simplification on the circuit above and we finally end up with an RC Circuit:

The circuit now has one resistance, which we call the membrane resistance, and a membrane battery.

What next?

Hopefully you can start to see both the complexity around modeling neurons and the necessity to create simpler models to make them computationally feasible - just look at the amount of simplification that was required for us to get to an RC Circuit!

But at least we can now look forward to implementing LIF.

Created: 2015-09-07 Mon 17:12

Emacs 24.5.1 (Org mode 8.2.10)

Validate

Saturday, September 05, 2015

Nerd Food: Neurons for Computer Geeks - Part IV: More Electricity

Nerd Food: Neurons for Computer Geeks - Part IV: More Electricity

Part I of this series looked at a neuron from above; Part II attempted to give us the fundamental building blocks in electricity required to get us on the road to modeling neurons. We did a quick interlude with a bit of coding in part III but now, sadly, we must return to boring theory once more.

Now that we grok the basics of electricity, we need to turn our attention to the RC circuit. As we shall see, this circuit is of particular interest when modeling neurons. The RC circuit is so called because it is a circuit, and it is composed of a Resistor and a Capacitor. We've already got some vague understanding of circuits and resistors, so lets start by having a look at this new crazy critter, the capacitor.

Capacitors

Just like the battery is a source of current, one can think of the capacitor as a temporary store of current. If you plug a capacitor into a circuit with just a battery, it will start to "accumulate" charge over time, up to a "maximum limit". But how exactly does this process work?

In simple terms, the capacitor is made up of two metal plates, one of which will connect to the positive end of the battery and another which connects to the negative end. At the positive end, the metal plate will start to lose negative charges because these are attracted to the positive end of the battery. This will make this metal plate positively charged. Similarly, at the negative end, the plate will start to accumulate negative charges. This happens because the electrons are repelled by the negative end of the battery. Whilst this process is taking place, the capacitor is charging.

At some point, the process reaches a kind of equilibrium, whereby the electrons in the positively charged plate are attracted equally to the plate as they are to the positive end of the battery, and thus stop flowing. At this point we say the capacitor is charged. It is interesting to note that both plates of the capacitor end up with the same "total" charge but different signs (i.e. -q and +q).

Capacitance

We mentioned a "maximum limit". A few things control this limit: how big the plates are, how much space there is between them and the kind of material we place between them, if any. The bigger the plates and the closer they are - without touching - the more you can store in the capacitor. The material used for the plates is, of course, of great importance too - it must be some kind of metal good at conducting.

In a more technical language, this notion of a limit is captured by the concept of capacitance, and is given by the following formula:

\begin{align} C = \frac{q}{V} \end{align}

Lets break it down to its components to see what the formula is trying to tell us. The role of V is to inform us about the potential difference between the two plates. This much is easy to grasp; since one plate is positively charged and other negatively charged, it is therefore straightforward to imagine that a charge will have a different electric potential in each plate, and thus that there will be an electric potential difference between them. q tells us about the magnitude of the charges that we placed on the plates - i.e. ignoring the sign. It wouldn't be to great a leap to conceive that plates with a larger surface area would probably have more "space" for charges and so a larger q - and vice-versa.

Capacitance is then the ratio between these two things; a measure of how much electric charge one can store for a given potential difference. It may not be very obvious from this formula, but capacitance is constant. That is to say, a given capacitor has a capacitance, influenced by the properties described above. This formula does not describe the discharging or charging process - but of course, capacitance is used in the formulas that describe those.

Capacitance is measured in SI units of Farads, denoted by the letter F. A farad is 1 coulomb over 1 volt:

\begin{align} 1F = \frac{C}{V} \end{align}

Capacitors and Current

After charging a capacitor, one may be tempted to discharge it. For that one could construct a simple circuit with just the capacitor. Once the circuit is closed, the negative charges will start to flow to the positively charged plate, at full speed - minus the resistance of the material. Soon enough both plates would be made neutral. At first glance, this may appear to be very similar to our previous circuit with a battery. However, there is one crucial difference: the battery circuit had a constant voltage and a constant current (for a theoretical battery) whereas a circuit with a discharging capacitor has voltage and current that decay over time. By "decaying", all we really mean is that we start at some arbitrarily high value and we move towards zero over a period of time. This makes intuitive sense: you cannot discharge the capacitor forever; and, as you discharge it, the voltage starts to decrease - for there are less charges in the plates and so less potential difference - and similarly, so does the current - for there is less "pressure" to make the charges flow.

This intuition is formally captured by the following equation:

\begin{align} I(t) = C \frac{dV(t)}{dt} \end{align}

I'm rather afraid that, at this juncture, we have no choice but to introduce Calculus. A proper explanation of Calculus a tad outside the remit of these posts, so instead we will have to make do with some common-sense but extremely hand-waved interpretations of the ideas behind it. If you are interested in a light-hearted but still comprehensive treatment of the subject, perhaps A Gentle Introduction To Learning Calculus may be to your liking.

Let's start by taking a slightly different representation of the formula above and then compare these two formulas.

\begin{align} i = C \frac{dv}{dt} \end{align}

In the first case we are talking about the current I, which normally is some kind of average current over some unspecified period. Up to now, time didn't really matter - so we got away with just talking about I in these general terms. This was the case with the Ohm's Law in part II. However, as we've seen, it is not so with capacitors - so we need to make the current specific to a point in time. For that we supply an "argument" to I - I(t); here, a mathematician would say that that I is a function of time. In the second case, we make use of i, which is the instantaneous current through the capacitor. The idea is that, somehow, we are able to know - for any point in time - what the instantaneous current is.

How we achieve that is via the magic of Calculus. The expression dv/dt in the second formula provides us with the instantaneous rate of change of the voltage over time. The same notion can be applied to V, as per first formula.

These formulas may sound awfully complicated, but what they are trying to tell us is that the capacitor's current has the following properties:

• it varies as a "function" of time; that is to say, different time points have different currents. Well, that's pretty consistent with our simplistic notion of a decaying current.
• it is "scaled" by the capacitor's capacitance C; "bigger" capacitors can hold on to higher currents for longer when compared to "smaller" capacitors.
• the change in electric potential difference varies as a function of time. This is subtle but also makes sense: we imagined some kind of decay for our voltage, but there was nothing to say the decay would remain constant until we reached zero. This formula tells us it does not; voltage may decrease faster or slower at different points in time.

Circuits: Parallel and Series

The RC circuit can appear in a parallel or series form, so its a good time to introduce these concepts. One way we can connect circuits is in series; that is, all components are connected along a single path, such that the current flows through all of them, one after the other. If any component fails, the flow will cease.

This is best understood by way of example. Lets imagine the canonical example of a battery - our old friend the 1.5V AA battery - and a three small light bulbs. A circuit that connects them in series would be made up of a cable segment plugged onto one of the battery's terminals - say +, then connected to the first light bulb. A second cable segment would then connect this light bulb to another light bulb, followed by another segment and another light bulb. Finally, a cable segment would connect the light build to the other battery terminal - say -. Graphically - and pardoning my inability to use Dia to create circuit diagrams - it would look more or less like this:

This circuit has a few interesting properties. First, if any of the light bulbs fail, all of them will stop working because the circuit is no longer closed. Second, if one were to add more and more light bulbs, the brightness of each light bulb will start to decrease. This is because each light bulb is in effect a resistor - the light shining being a byproduct of said resistance - and so they are each decreasing the current. So it is that in a series circuit the total resistance is given by the sum of all individual resistances, and the current is the same for all elements.

Parallel circuits are a bit different. The idea is that two or more components are connected to the circuit in parallel, i.e. there are two or more paths along which the current can flow at the same time. So we'd have to modify our example to have a path to each of the light bulbs which exists in parallel to the main path - quite literally a segment of cable that connects the other segments of cable, more or less like so:

Here you can see that if a bulb fails, there is still a closed loop in which current can flow, so the other bulbs should be unaffected. This also means that the voltage is the same for all components in the circuit. Current and resistance are now "relative" to each component, and it is possible to compute the overall current for the circuit via Kirchhoff's Current Law. Simplifying it, it means that the current for the circuit is the sum of all currents flowing through each component.

This will become significant later on when we finally return to the world of neurons.

The RC Circuit

With all of this we can now move to the RC circuit. In its simplest form, the circuit has a source of current with a resistor and a capacitor:

Let's try to understand how the capacitor's voltage will behave over time. This circuit is rather similar to the one we analysed when discussing capacitance, with the exception that we now have a resistor as well. But in order to understand this, we must return to Kirchhoff's current law, which we hand-waved a few paragraphs ago. Wikipedia tells us that:

The algebraic sum of currents in a network of conductors meeting at a point is zero.

One way to understand this statement is to think that the total quantity of current entering a junction point must be identical to the total quantity leaving that junction point. If we consider entering to be positive and leaving to be negative, that means that adding the two together must yield zero.

Because of Kirchhoff's law, we can state that, for the positive terminal of the capacitor:

\begin{align} i_c(t) + i_r(t) = 0 \end{align}

That is: at any particular point in time t, the current flowing through the capacitor added to the current flowing through the resistor must sum to zero. However, we can now make use of the previous formulas; after all, our section on capacitance taught us that:

\begin{align} i_c(t) = C \frac{dv(t)}{dt} \end{align}

And making use of Ohm's Law we can also say that:

\begin{align} i_r(t) = \frac{v(t)}{R} \end{align}

So we can expand the original formula to:

\begin{align} C \frac{dv(t)}{dt} + \frac{v(t)}{R} \end{align}

Or:

\begin{align} C \frac{dV}{dt} + \frac{V}{R} \end{align}

I'm not actually going to follow the remaining steps to compute V, but you can see them here and they are fairly straighforward, or at least as straightforward as calculus gets. The key point is, when you solve the differential equation for V, you get:

\begin{align} V(t) = V_0e^{-\frac{t}{RC}} \end{align}

With V0 being voltage when time is zero. This is called the circuit's natural response. This equation is very important. Note that we are now able to describe the behaviour of voltage over time with just a few inputs: the starting voltage, the time, the resistance and the capacitance.

A second thing falls off of this equation: the RC Time constant, or τ. It is given by:

\begin{align} \tau = RC \end{align}

The Time Constant is described in a very useful way in this page, so I'll just quote them and their chart here:

The time required to charge a capacitor to 63 percent (actually 63.2 percent) of full charge or to discharge it to 37 percent (actually 36.8 percent) of its initial voltage is known as the TIME CONSTANT (TC) of the circuit.

What next?

Now we understand the basic behaviour of the RC Circuit, together with a vague understanding of the maths that describe it, we need to return to the neuron's morphology. Stay tuned.

Created: 2015-09-05 Sat 18:56

Emacs 24.5.1 (Org mode 8.2.10)

Validate

Friday, September 04, 2015

Nerd Food: Neurons for Computer Geeks - Part III: Coding Interlude

Nerd Food: Neurons for Computer Geeks - Part III: Coding Interlude

If you are anything like me, the first two parts of this series have already bored you silly with theory (Part I, Part II) and you are now hankering for some code - any code - to take away the pain. So part III is here to do exactly that. However, let me prefix that grandiose statement by saying this is not the best code you will ever see. Rather, its just a quick hack to introduce a few of the technologies we will make use of for the remainder of these series, namely:

• CMake and Ninja: this is how we will build our code.
• Wt: provides a quick way to knock-up a web frontend for C++ code.
• Boost: in particular Boost Units and later on Boost OdeInt. Provides us with the foundations for our numeric work.

What I mean by a "quick hack" is: there is no validation, no unit tests, no "sound architecture" and none of the things you'd expect from production code. But it should serve as an introduction to modeling in C++.

All the code is available in GitHub under neurite. Lets have a quick look at the project structure.

CMake

We just took a slimmed down version of the Dogen build system to build this code. We could have gotten away with a much simpler CMake setup, but I intend to use it for the remainder of this series so that's why its a bit more complex than what you'd expect. It is made up of the following files:

• Top-level CMakeLists.txt: ensures all of the dependencies can be found and configured for building, sets up the version number and debug/release builds.
• build/cmake: any Find* scripts that are not supplied with the CMake distribution. We Google for these and copied them here.
• projects/CMakeLists.txt: sets up all of the compiler and linker flags we need to build the project. Uses pretty aggressive flags such as -Wall and -Werror.
• projects/ohms_law/src/CMakeLists.txt: our actual project, the bit that matters for this article.

ohms_law Project

The project is made up of two classes, in files calculator.[hc]pp and view.[hc]pp. The names are fairly arbitrary but they try to separate View from Model: the user interface is in view and the "number crunching" is in calculator.

The View

Lets have a quick look at view. In the header file we simply define a Wt application with a few widgets:

class view : public Wt::WApplication {
public:
view(const Wt::WEnvironment& env);

private:
Wt::WLineEdit* current_;
Wt::WLineEdit* resistance_;
Wt::WText* result_;
};

It is implemented in an equally trivial manner. We just setup the widgets and hook them together. Finally, we create a trivial event handler that performs the "computations" when the button is clicked.

view::view(const Wt::WEnvironment& env) : Wt::WApplication(env) {
setTitle("Ohm's Law Calculator");

current_ = new Wt::WLineEdit(root());
current_->setValidator(new Wt::WDoubleValidator());
current_->setFocus();

resistance_ = new Wt::WLineEdit(root());
resistance_->setValidator(new Wt::WDoubleValidator());

Wt::WPushButton* button = new Wt::WPushButton("Calculate!", root());
button->setMargin(5, Wt::Left);
result_ = new Wt::WText(root());

button->clicked().connect([&](Wt::WMouseEvent&) {
const auto current(boost::lexical_cast<double>(current_->text()));
const auto resistance(boost::lexical_cast<double>(resistance_->text()));

calculator c;
const auto voltage(c.voltage(resistance, current));
const auto s(boost::lexical_cast<std::string>(voltage));
result_->setText("Voltage: " + s);
});
}

The Model

The model is equally as simple as the view. It is made up of a single class, calculator, whose job is to compute the voltage using Ohm's Law. It does this by making use of Boost Units. This is obviously not necessary, but we wanted to take the opportunity to explore this library as part of this series of articles.

double calculator::
voltage(const double resistance, const double current) const {
boost::units::quantity<boost::units::si::resistance>
R(resistance * boost::units::si::ohms);
boost::units::quantity<boost::units::si::current>
I(current * boost::units::si::amperes);
auto V(R * I);
return V.value();
}

Compiling and Running

If you are on a debian-based distribution, you can do the following steps to get the code up and running. First install the dependencies:

$sudo apt-get install libboost-all-dev witty-dev ninja-build cmake clang-3.5  Then obtain the source code from GitHub: $ git clone https://github.com/mcraveiro/neurite.git

Now you can build it:

cd neurite
mkdir output
cd output
cmake ../ -G Ninja
ninja -j5

If all went according to plan, you should be able to run it:

\$ stage/bin/neurite_ohms_law --docroot . --http-address 0.0.0.0 --http-port 8080

Now using a web browser such as chrome, connect to http://127.0.0.1:8080 and you should see a "shiny" Ohm's Law calculator! Sorry, just had to be done to take away the boredom a little bit. Lets proceed with the more serious matters at hand, with the promise that the real code will come later on.

Created: 2015-09-04 Fri 17:16

Emacs 24.5.1 (Org mode 8.2.10)

Validate

Monday, August 31, 2015

Nerd Food: Neurons for Computer Geeks - Part II: The Shocking Complexity of Electricity

Nerd Food: Neurons for Computer Geeks - Part II: The Shocking Complexity of Electricity

In part I we started to describe the basic morphology of the neuron. In order to continue, we now need to take a detour around the world of electricity. If you are an electricity nerd, I apologise in advance; this is what happens when a computer scientist escapes into your realm, I'm afraid.

First and foremost, we need to understand the concept of charge. It is almost a tautology that atoms are made up of "sub-atomic" particles. These are the proton, the neutron and the electron. The neutron is not particularly interesting right now; however the electron and the proton are, and all because they have a magical property called charge. For our purposes, it suffices to know that "charge" means that certain sub-atomic particles attract or repeal each other, according to a well defined set of rules.

You can think of a charge as a property attached to the sub-atomic particle, very much like a person has a weight or height, but with a side-effect; it is as if this property makes people push or hug each other when they are in close proximity, and they do so with the same strength when at the same distance. This "strength" is the electric force. How they decide whether to hug or push the next guy is based on the "sign" of the charge - that is, positive or negative - with respect to their own charge "sign". Positives push positives away but hug negatives and vice-versa.

For whatever historical reasons, very clever people decided that an electron has one negative unit of charge and a proton has a positive unit of charge. The sign is, of course, rather arbitrary. We could have just as well said that protons are red and electrons are blue or some other suitably binary-like convention to represent these permutations. Just because protons and electrons have the same charge, it does not follow that they are similar in other respects. In fact, they are very different creatures. For example, the electron is very "small" when compared to the proton - almost 2000 times "smaller". The relevance of this "size" difference will become apparent later on. Physicists call this "size" mass, by the by.

As it happens, all of these sub-atomic crazy critters are rather minute entities. So small in fact that it would be really cumbersome if we had to talk about charges in terms of the charge of an electron; the numbers would just be too big and unwieldy. So, the very clever people came up with a sensible way to bundle up the charges of the sub-atomic particles in bigger numbers, much like we don't talk about millimetres when measuring the distance to the Moon. However, unlike the nice and logical metric system, with its neat use of the decimal system, physicists came up instead with the Coulomb, or C, one definition of which is:

• 1 Coloumb (1C) = 6.241 x 1018 protons
• -1 Coloumb (-1C) = 6.241 x 1018 electrons

This may sound like a very odd choice - hey, why not just 1 x 1020 or some other "round" number? - but just like a kilobyte is 1024 bytes rather 1000, this wasn't done by accident either. In fact, all related SI units were carefuly designed to work together and make calculations as easy as possible.

Anyway, whenever you see q or Q in formulas it normally refers to a charge in Coulombs.

Units, Dimensions, Measures, Oh My!

Since we are on the subject of SI, this is probably a good point to talk about units, dimensions, measurements, magnitudes, conversions and other such exciting topics. Unfortunately, these are important to understand how it all hangs together.

A number such as 1A makes use of the SI unit of measure "Ampere" and it exists in a dimension: the dimension of all units which can talk about electric charges. This is very much in the same way we can talk about time in seconds or minutes - we are describing points in the time dimension, but using different units of measure - or just units, because we're lazy. A measurement is the recording of a quantity with a unit in a dimension. Of course, it would be too simple to call it a "quantity", so instead physicists, mathematicians and the like call it magnitude. But for the lay person, its not too bad an approximation to replace "magnitude" with "quantity".

Finally, it is entirely possible to have compound dimensional units; that is, one can have a unit of measure that refers to more than one dimension, such as say "10 kilometres per second".

I won't discuss conversions just now, but you can easily imagine that formulas that contain multiple units may provide ways to convert from one unit to another. This will become relevant later on.

Go With the Flow

Now we have a way of talking about charge, and now we know these things can move - since they attract and repel each other - the next logical thing is to start to imagine current. The name sounds magical, but in reality it is akin to a current in a river: you are just trying to figure out how much water is coming past you every second (or in some other suitable unit in the time dimension). The exact same exercise could be repeated for the number of cars going past in a motorway or the number of runners across some imaginary point in a track. For our electric purposes, current tells you how many charges have zipped past over a period of time.

In terms of SI units, current is measured in Amperes, which have the symbol A; an Ampere tells us how many Coloumbs have flown past in a second. Whenever you see I in formulas it normally refers to current.

Now lets see how these two things - Coulombs and Amperes - could work together. Lets imagine an arbitrary "pipe" between two imaginary locations, one side of which with a pile of positive charges and, on the other side, a pile of negative charges - both measured in Coulombs, naturally. In this extraordinarily simplified and non-existing world, the negative charges would "flow" down the pipe, attracted by the positive charges. Because the positive charges are so huge they won't budge, but the negative charges - the lighter electrons - would zip across to meet them. The number of charges you see going past in a time tick is the current.

Resist!

Going back to our example of current in a river, one can imagine that some surfaces are better at allowing water to flow than others; for example, a river out in the open is a lot less "efficient" at flowing than say a plastic pipe designed for that purpose. One reason is that the river has to deal with twists and turns as it finds a path over the landscape whereas the pipe could be laid out as straight as possible; but it is also that the rocks and other elements of the landscape slow down water, whereas a nice flat pipe would have no such impediments. If one were to take these two extremes - a plastic pipe designed for maximum water flow versus a landscape - one could see that they affect flow differently; and one could be tempted to name the property of "slowing down the flow" resistance, because it describes how much "resistance" these things are offering to the water. If you put up a barrier to avoid flooding, you probably would want it to "resist" water quite a lot rather than allow it to flow; and you can easily imagine that sand and sandbags "resist" water in very different ways.

Resistance is a fundamental concept in the electrical world. The gist of it is similar to the contrived examples above, in that not all materials behave the same way with regards to allowing charges to flow. Some allow them to flow freely nearly at maximum speed whereas others do not allow them to flow at all.

Since we are dealing with physics, it is of course possible to measure resistance. We do so in SI units of Ohms, denoted by the Greek letter upper-case Ω.

As we shall see, not all materials are nicely behaved when it comes to resistance.

You've Got Potential Baby!

Lets return to our non-existing "pipe that allows charges to flow" scenario, and take it one step further. Imagine that for whatever reason our pipe becomes clogged up with a blockage somewhere in the middle. Nothing could actually flow due to this blockage so our current drops to zero.

According to the highly simplified rules that we have learned thus far, we do know that - were there to be no blockage - there would be movement (current). That is, the setup of the two bundles in space is such that, given the right conditions, we would start to see things flowing. But, alas, we do not have the right conditions because the pipe is blocked; hence no flow. You could say this setup has "the potential" to get some flow going, if only we could fix the blockage.

In the world of electricity, this idea is captured by a few related concepts. If we highly simplify them, they amount to this:

• electric potential: the idea that depending where you place a charge in space, it may have different "potential" to generate energy. We'll define energy a bit better latter on, but for now a layman's idea of it suffices. By way of an example: if you place a positive charge next to a lump of positive charges and let it go, it will move a certain distance away from the lump. Before you let the charge go, you know the charge has potential to move away. You can also see that the charge will move by different amounts depending how close you place it to the lump; the closer you place it, the more it will move. When we are thinking of electric potential, we think of just one charge.
• electric potential energy: clearly it would be possible to move two or three charges too, as we did for the one; and clearly they should produce more energy than a single charge. So one simple way of understanding electric potential energy is to think of it as the case of electric potential that deals with the total number of charges we're interested in, rather than just one.

Another way of imagining these two concepts is to think that electric potential is a good way to measure things when you don't particularly care about the number of charges involved; it is as if you scaled everything to just one unit of charge. Electric potential energy is more when you are thinking of a system with an actual number of charges. But both concepts deal with the notion that placing a charge at different points in space may have an impact in the energy you can get out of it.

Having said all of that we can now start to think about electric potential difference. It uses the same approach as electric potential, in that everything is scaled to just one unit of charge, but as the name implies, it provides a measurement of the difference between the electric potential of two points. Electric potential difference is more commonly known as voltage. Interestingly, it is also known as electric pressure, and this may be the most meaningful of its names; this is because when there is an electric potential difference, it applies "pressure" on charges which force them to move.

The SI unit Volt is used to measure electric potential, electric potential energy and electric potential difference amongst other things. This may sound a bit weird at first, but it is just because one is unfamiliar with these concepts. Take time, for example: we use minutes as a unit of measure of all sorts of things (duration of a football game, time it takes for the moon to go around the earth, etc.). We did not invent a new unit for each phenomenon because we recognised - at some point - that we were dealing with points in the same dimension.

Quick Conceptual Mop-Up

Before we move over to the formulas, it may be best to tie up a few loose ends. These are not strictly necessary, but just make the picture a bit more complete and moves us to a more realistic model - if still very simplistic.

First, we should start with atoms; we mentioned charges but skipped them. Atoms are (mostly) a stable arrangement of charges, placed in such a way that the atoms themselves are neutral - i.e. contain exactly the same amount of negative and positive charges. We mentioned before that protons and electrons don't really get along, and neutrons are kind of just there, hanging around. In truth, neutrons and protons also really get along, via the aptly named nuclear force; this is what binds them together in the nucleus of the atom. Electrons are attracted to protons and live their existences in a "cloud" around the nucleus. Note that the nucleus is more than 99% of the mass of the atom, which gives you an idea of just how small electrons are.

The materials we will deal with in our examples are made of atoms, as are, well, quite a few things in the universe. These materials are themselves stable arrangements of atoms, just like atoms are stable arrangements of protons, neutrons and electrons. As you can see in the picture, these look like lattices of some kind.

In practice, copper wires are made up of a great many things rather than just atoms of copper. One such "kind of thing" is the unbound electrons - or free-moving electrons; basically electrons are not trapped into an atom. As we mentioned before, electrons are the ones doing most of the moving. Left to their own devices, electrons in a conducting material will just move around, bumping into atoms in a fairly random way. However, lets say you take one end of a copper wire and plug it to the + side of a regular AA battery and then take other end and plug it to the - side of the battery. According to all we've just learned, its easy to imagine what will happen: the electrons stored in the - side will zip across the copper to meet their proton friends at the other end. This elemental construction, with its circular path, is called a circuit. What you've done is to upset the neutral balance of the copper wire and got all the electrons to move in a coordinated way (rather than random) from the - side to the + side.

It is at this juncture that we must introduce the concept of ions. An ion is basically an atom that is no longer neutral - either because it has more protons than electrons (called a cation) or more electrons than protons (called an anion). In either case, this comes about because the atom has gained or lost some electrons. Ions will become of great interest when we return to the neuron.

One final word on resistance and its sister concept of conductance:

• Resistance is in effect a byproduct of the way the electrons are arranged in the electron cloud and is related to the ionisation mentioned above; certain arrangements just don't allow electrons to flow across.
• Conductance is the inverse of resistance. When you talk about resistance you are focusing on the material's ability to impair movement of charges; when you talk about conductance you are focusing on the material's ability to let charge flow through.

The reason we choose copper or other metals for our examples is because they are good at conducting these pesky electrons.

Ohm's Law

We have now introduced all the main actors required for one of the main parts in the play: Ohm's Law. It can be stated very easily:

V = R x I

And here's a picture to aid intuition.

The best way to understand this law is to create a simple circuit.

On the left we have a voltage source, which could be our 1.5V AA battery. On the right of the diagram we have a resistor - an electric component that is designed specifically to "control" the flow of the electric current. Without the resistor, we would be limited by how much current the battery can pump out and how much "natural" resistance the copper wire has, which is not a lot since it is very good at conducting. The resistor gives us a way to limit current flow from these theoretical maximum limitations.

Even if you are not particularly mathematically oriented, you can easily see that Ohm's Law gives us a nice way to find any of these three variables, given the other two. That is to say:

R = V / I
I = V / R

These tell us many interesting things such as: for the same resistance, current increases as the voltage increases. For good measure, we can also find out the conductance too:

G = I / V = 1 / R

It is important to notice that not everything obeys Ohm's law - i.e. behave in a straight line. The conductors that obey this law are called ohmic conductors. Those that do not are called non-ohmic conductors. There are also things that obey to Ohm's Law, for the most part. These are called quasi-ohmic.

What next?

We have already run out of time for this instalment but there are still some more fundamental electrical concepts we need to discuss. The next part will finish these and start to link them back to the neuron.

Created: 2015-08-31 Mon 19:27

Emacs 24.5.1 (Org mode 8.2.10)

Validate


text:
# Finding all the solutions to a system of equations

I'm struggling with something that I think should be pretty basic. I am taking a multi-variable calculus course at university where we are finding relative max/mins and saddle points of multi-variable functions. On some of these problems, I can find a couple of critical points, but can't seem to find all of them, for instance: $$f(x, y) = 2xy - \frac12(x^4 + y^4) + 1$$

I find the partial derivatives of x and y and get: $$f_x(x, y) = 2y - 2x^3$$ $$f_y(x, y) = 2x - 2y^3$$

I set both of these to 0 and get a system of equations. Eventually I end up with a $y=x^3$ and subbing that into my other equation gives me: $$2x(1-x^5)=0$$

From this, I can come up with the answers $x=0$, and $x=1$. However, I also know from graphing this function that the remaining critical point is $x=-1$. I am sure that I just need to factor out the $(1-x^5)$ further, but I do not know a convenient way to do that. I'll have to be doing these fairly quickly for an upcoming exam. Any advice?

• Powers of powers multiply, not add. – Michael Burr Oct 29 '17 at 20:51

your System is given by $$y=x^3$$ $$x=y^3$$ thus $x=x^9$ and you will get $$0=x(x^8-1)$$ note that $$x^8-1=\left( x-1 \right) \left( x+1 \right) \left( {x}^{2}+1 \right) \left( {x}^{4}+1 \right)$$


text:
# Binomial Heaps in Data Structure

A binomial Heap is a collection of Binomial Trees. A binomial tree Bk is an ordered tree defined recursively. A binomial Tree B0 is consists of a single node.

A binomial tree Bk is consisting of two binomial tree Bk-1. That are linked together. The root of one is the left most child of the root of the other

Some binomial heaps are like below −

Some properties of binomial trees are −

• Binomial tree with Bk has 2k nodes.

• Height of the tree is k

• There are exactly $$\left(\begin{array}{c}k\ j\end{array}\right)$$ nodes at depth i for all i in range 0 to k

## Binomial Heap

A binomial heap H is a set of binomial trees. There are some properties.

• Each binomial tree in H is heap-ordered. So the key of a node is greater than or equal to the key of its parent.

• There is at most one binomial tree in H, whose root has a given degree.

## Example of Binomial Heap

This binomial Heap H consists of binomial trees B0, B2 and B3. Which have 1, 4 and 8 nodes respectively. And in total n = 13 nodes. The root of binomial trees are linked by a linked list in order of increasing degree


text:
# What does mean conv{e_1,−e_l,…,e_d,−e_d} and conv{{+1,-1}^d}. I could not understand, need a simple explanation.

What does mean $\mathrm{c}\mathrm{o}\mathrm{n}\mathrm{v}\left\{{e}_{1},-{e}_{l},\dots ,{e}_{d},-{e}_{d}\right\}$ and $\mathrm{c}\mathrm{o}\mathrm{n}\mathrm{v}\left\{\left\{+1,-1{\right\}}^{d}\right\}.$
I could not understand, need a simple explanation.
You can still ask an expert for help

• Questions are typically answered in as fast as 30 minutes

Solve your problem for the price of one coffee

• Math expert for every subject
• Pay only if we can solve it

Cremolinoer
Let us consider the case d=3.
The set $\left\{\left\{+1,-1{\right\}}^{d}\right\}$ is the set of all triples (there are ${2}^{3}=8$ of them)
$\left\{\left(-1,-1,-1\right),\left(-1,-1,1\right),\left(-1,1,-1\right),\cdots \left(1,1,1\right)\right\}$
i.e., the vertices of a cube.
More generally, $\left\{+1,-1{\right\}}^{d}$ is the set of vertices of a hypercube in ${\mathbb{R}}^{\mathbb{d}}$
As a consequence:
$\mathrm{c}\mathrm{o}\mathrm{n}\mathrm{v}\left\{\left\{+1,-1{\right\}}^{d}\right\}$
is the "solid hypercube" in ${\mathbb{R}}^{d}$


text:
# $e$ and $\pi$ Spoof

It is known that that $\pi$ and $e$ are transcendental. $e$ was proven to be transcendental by Hermite in 1873, and $\pi$ by Lindemann in 1882. $e^{\pi}$ is transcendental from the Gelfond's Theorem. It is still not known if $e^e,$ $\pi ^\pi$ or $\pi ^e$ are transcendental. However, below is a proof that $\pi ^e$ is rational. It comes from E. Barbeau's Mathematical Fallacies, Flaws, and Flimflam which is a collection of his columns The College Mathematical Journal. The proof has been contributed by Christian Counts.

### Theorem

$\pi ^e$ is rational.

### Proof

First off, for a rational $r,$ $\log_{\pi}r$ is irrational because, otherwise, the equation $\pi ^s=r,$ with rational $r,$ would have a rational solution which is impossible given that $\pi$ is transcendental.

Now suppose, if possible, that $\pi ^e \not\in \mathbb{Q}.$ Then, for all $r\in\mathbb{Q},$ $\pi ^e\ne r,$ so that $e=\log_{\pi}\pi ^e\ne\log_{\pi}r$ because the logarithm is a 1-1 function. Therefore, as was observed, $e\ne k$ for $k\not\in\mathbb{Q}.$ In other words, $e$ is rational. But this is a contradiction. It follows that $\pi ^e$ is rational as claimed.

### References

1. E. J. Barbeau, Mathematical Fallacies, Flaws, and Flimflam, MAA, 2000, p. 10


text:
A module to simplify using pytest for AiiDA plugins.

## Project description

NOTE: The aiida-pytest package is in maintenance mode: bugs will continue to be fixed for the foreseeable future, but no new features will be implemented. Users considering using aiida-pytest are strongly encouraged to use the built-in AiiDA fixtures instead.

# aiida-pytest

This is a helper to enable testing AiiDA plugins with pytest. The main purpose is to create a fixture which sets up a temporary AiiDA database and user, and simplify setting up the computers and calculations.

To get started, create a tests folder where your pytest tests will be located. In conftests.py, you need to write

from aiida_pytest import *

This defines the configure and configure_with_daemon fixtures. To set up computers and codes for the test run, you need a config.yml file in the tests folder (and run pytest from there). The following example config file sets up localhost and the bands-inspect code:

computers:
localhost:
hostname: localhost
description: localhost
transport: local
scheduler: direct
work_directory: /tmp/test_aiida
prepend_text: 'unset PYTHONPATH'

codes:
bands_inspect:
description: bands_inspect code
default_plugin: bands_inspect.difference
remote_computer: localhost
remote_abspath: /home/a-dogres/.virtualenvs/bands-inspect/bin/bands-inspect

Note: aiida-pytest is not compatible with the aiida-xdist plugin, since the fixtures with scope=session are then called for each running worker.

## Defining and running tests

Tests with aiida-pytest are defined and run exactly like "regular" pytest tests. If a test needs the AiiDA database, it should use the configure fixture. If the test also requires the Daemon to run, it should use the configure_with_daemon fixture. Note that, since certain AiiDA import statements require the database backend to be set, these imports should be done inside the test function.

After the tests have run, the code will wait for you to press Enter before deleting the testing database and repository. This gives you the opportunity to manually inspect the final state. If you want to avoid this step (for example in a CI system), pass the --quiet-wipe flag to py.test.

## Project details

Uploaded source
Uploaded py3


text:
Question

# A balloon blown with 1 mol of a gas, has a volume of 480 ml at 5∘C. If the balloon is filled to 78 th of its maximum capacity, then which of the following is/ are correct? The balloon will burst at 30∘C The pressure of the gas inside the balloon at 5∘C is 47.5 atm The minimum temperature at which the balloon will burst is 47.71∘C The pressure of gas when balloon burst at minimum temperature is 50 atm.

Solution

## The correct options are B The pressure of the gas inside the balloon at 5∘C is 47.5 atm C The minimum temperature at which the balloon will burst is 47.71∘C Max capacity of balloon =87×480=548.57 ml Also, V1=480 ml, T1=278K, n=1 mol ∵V1T1=V2T2 ⇒480278=548.57T2 ⇒T2=317.71K=44.71∘C From PV=nRT P×4801000=1×0.0821×278 ⇒P=47.5 atm

Suggest corrections


text:
# How do I get \DeclareMathOperator to put the limit beneath? [duplicate]

I use at the picture above: \DeclareMathOperator{\vo}{vol}
And this is the complete line:

$\lim_{a}=\vo_{a}$

I can make that the a will be below the vol? (like the lim).

Thank you!!

Use the starred version of the command: \DeclareMathOperator*
\documentclass{article}
$\lim_{a}=\vo_{a}$


text:
# Generalization of a Factorial Problem

Find the smallest positive integer $$n$$ such that $$n!$$ has $$z$$ zeroes.

Try to generalize the following problem.

Note by Swapnil Das
2 years, 6 months ago

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold
- bulleted- list
• bulleted
• list
1. numbered2. list
1. numbered
2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1paragraph 2

paragraph 1

paragraph 2

[example link](https://brilliant.org)example link
> This is a quote
This is a quote
    # I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in $$...$$ or $...$ to ensure proper formatting.
2 \times 3 $$2 \times 3$$
2^{34} $$2^{34}$$
a_{i-1} $$a_{i-1}$$
\frac{2}{3} $$\frac{2}{3}$$
\sqrt{2} $$\sqrt{2}$$
\sum_{i=1}^3 $$\sum_{i=1}^3$$
\sin \theta $$\sin \theta$$
\boxed{123} $$\boxed{123}$$

## Comments

Sort by:

Top Newest

In the question of Zeroes all around by Akshat Sharda, I generalize the formula as $z = \sum_{i=1}^{\left \lfloor log_5n \right \rfloor} \left \lfloor \frac{n}{5^i} \right \rfloor$

and Akshat Sharda himself provided that the quick approximation is $$n = 4z$$. To find the exact form, it is necessary to add a few more number to this sum to find the right $$n$$

- 2 years, 6 months ago

Log in to reply

Oh Yes !!

- 2 years, 6 months ago

Log in to reply

Great generalization!

- 2 years, 6 months ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...


text:
New interface

# Graph Isomorphism for $(H_1,H_2)$-Free Graphs: An Almost Complete Dichotomy

1 GOAL - Graphes, AlgOrithmes et AppLications
LIRIS - Laboratoire d'InfoRmatique en Image et Systèmes d'information
Abstract : Abstract We resolve the computational complexity of Graph Isomorphism for classes of graphs characterized by two forbidden induced subgraphs $H_{1}$ H 1 and $H_2$ H 2 for all but six pairs $(H_1,H_2)$ ( H 1 , H 2 ) . Schweitzer had previously shown that the number of open cases was finite, but without specifying the open cases. Grohe and Schweitzer proved that Graph Isomorphism is polynomial-time solvable on graph classes of bounded clique-width. Our work combines known results such as these with new results. By exploiting a relationship between Graph Isomorphism and clique-width, we simultaneously reduce the number of open cases for boundedness of clique-width for $(H_1,H_2)$ ( H 1 , H 2 ) -free graphs to five.
Document type :
Journal articles
Domain :

https://hal.archives-ouvertes.fr/hal-03394356
Contributor : Nicolas Bousquet Connect in order to contact the contributor
Submitted on : Friday, October 22, 2021 - 8:47:07 AM
Last modification on : Friday, September 30, 2022 - 11:34:16 AM

### Citation

Nicolas Bousquet, Marthe Bonamy, Konrad Dabrowski, Matthew Johnson, Daniël Paulusma, et al.. Graph Isomorphism for $(H_1,H_2)$-Free Graphs: An Almost Complete Dichotomy. Algorithmica, 2021, 83 (3), pp.822-852. ⟨10.1007/s00453-020-00747-x⟩. ⟨hal-03394356⟩

Record views


text:
# 7.8. Medium Multiple Choice Questions¶

These problems are similar to those you will see on the AP CS A exam.

6-8-1: How many stars are output when the following code is executed?

for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++)
System.out.println("*");
}

• 10
• The second loop executes 5 times for each of the 5 times the first loop executes, so the answer should be 5 * 5.
• 5
• The second loop executes 5 times for each of the 5 times the first loop executes, so the answer should be 5 * 5.
• 25
• The first loop will execute 5 times, and for each time through, the second loop will execute 5 times. So the answer is the number of times through the first loop times the number of times through the second.
• 50
• The second loop executes 5 times for each of the 5 times the first loop executes, so the answer should be 5 * 5.
• 15
• The second loop executes 5 times for each of the 5 times the first loop executes, so the answer should be 5 * 5.

6-8-2: Which of the following code segments will produce the displayed output?

1
22
333
4444
55555

I.   for (int i = 1; i <= 5; i++) {
for (int j = i; j > 0; j--) {
System.out.print(i);
}
System.out.println();
}

II.  for (int i = 0; i < 5; i++) {
for (int j = 0; j < i; j++) {
System.out.print(i);
}
System.out.println();
}

III. for (int i = 1; i < 5; i++) {
for (int j = i; j > 0; j--) {
System.out.print(i);
}
System.out.println();
}

IV.  for (int i = 1; i < 6; i++) {
for (int j = 0; j < i; j++) {
System.out.println(i);
}
}

V.   for (int i = 0; i < 5; i++) {
for (int j = 0; j < i; j++) {
System.out.print(i+1);
}
System.out.println();
}

• I
• This will loop with i changing from 1 to 5 and then for each i, j will loop from i to 0 printing the value of i and then a new line.
• II
• This will loop i from 0 to 4 and j from 0 to i, neglecting to ouput 5.
• III
• This will loop with i changing from 1 to 4 and j from i to 0.
• IV
• This will loop with i changing from 1 to 5 and j from 0 to i but it will print each value on a different line.
• V
• This will loop with i changing from 0 to 4 and j from 0 to i.

6-8-3: What is printed as a result of the following code segment?

for (int k = 0; k < 20; k+=2) {
if (k % 3 == 1)
System.out.println(k + " ");
}

• 0 2 4 6 8 10 12 14 16 18
• This would be correct if we were printing out all of the values of k, not just the ones that have a remainder of 1 when divided by 3.
• 4 16
• This is missing the value 10 (10 divided by 3 does have a remainder of 1).
• 0 6 12 18
• None of these answers have a remainder of 1 when divided by 3.
• 1 4 7 10 13 16 19
• This answer would be correct if k was incremented by 1 instead of 2. K will be 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 in this loop.
• 4 10 16
• This will loop with k having a value of 0 to 18 (it will stop when k = 20). It will print out the value of k followed by a space when the remainder of dividing k by 3 is 1.

6-8-4: Which of the following code segments will produce the displayed output?

11111
2222
333
44
5

I.   for (int j = 1; j <= 5; j++) {
for (int k = 5; k >= j; k--) {
System.out.print(j + " ");
}
System.out.println();
}

II.  for (int j = 1; j <= 5; j++) {
for (int k = 5; k >= 1; k--) {
System.out.print(j + " ");
}
System.out.println();
}

III. for (int j = 1; j <= 5; j++) {
for (int k = 1; k <= j; k++) {
System.out.print(j + " ");
}
System.out.println();
}

IV.  for (int j = 1; j <= 5; j++) {
for (int k = 1; k <= 5; k++) {
System.out.println(j + " ");
}
}

V.   for (int j = 1; j <= 5; j++) {
for (int k = j; k <= 5; k++) {
System.out.print(k + " ");
}
System.out.println();
}

• I
• This will loop with j from 1 to 5 and k from 5 to j and print out the value of j and a space. So the first time through the loop it will print 1 five times and the next time it will print out 2 four times and so on.
• II
• This will print out each value from 1 to 5 five times.
• III
• This will loop with j from 1 to 5 and k from 1 times.
• IV
• This will loop j from 1 to 5 and k from 1 to 5, printing each number 5 times.
• V
• This loops with j from 1 to 5 and k from j to 5 and prints out the value of k, printing 1 through 5 on the first line, 2 through 5 on the next, and so on.

6-8-5: What are the values of var1 and var2 after the following code segment is executed and the while loop finishes?

int var1 = 0;
int var2 = 2;

while ((var2 != 0) && ((var1 / var2) >= 0)) {
var1 = var1 + 1;
var2 = var2 - 1;
}

• var1 = 0, var2 = 2
• This would be true if the body of the while loop never executed. This would have happened if the while check was if var1 != 0 instead of var2 != 0
• var1 = 1, var2 = 1
• This would be true if the body of the while loop only execued one time, but it executes twice.
• var1 = 3, var2 = -1
• This would be true if the body of the while loop executed 3 times, but it executes twice.
• var1 = 2, var2 = 0
• The loop starts with var1=0 and var2=2. The while checks that var2 isn't 0 and that var1/var2 is greater than or equal to zero (0/2=0) so this is equal to zero and the body of the while loop will execute. The variable var1 has 1 added to it for a new value of 1. The variable var2 has 1 subtracted from it for a value of 1. At this point var1=1 and var2=1. The while condition is checked again. Since var2 isn't 0 and var1/var2 (1/1=1) is >=0 so the body of the loop will execute a second time. The variable var1 has 1 added to it for a new value of 2. The variable var2 has 1 subtracted from it for a value of 0. At this point var1=2 and var2=0. The while condition is checked again. Since var2 is zero the while loop stops and the value of var1 is 2 and var2 is 0.
• The loop won't finish executing because of a division by zero.
• 0/2 won't cause a division by zero. The result is just zero.
Next Section - 7.9. Hard Multiple Choice Questions


text:
# Tag Info

16

There was an update for Array, not done to the end. The method below does not work for earlier versions even though that Array is New in 1 | Last modified in 4 Moreover WRI forgot to update docs for error messages: Array::plen - the first example gives no error in V9. V9 Array[# &, n, {start, stop}] Array[# &, 10, {-1, 1}] {-1, ...

12

There are nice trigonometric formulas δ = 0.01; trg[x_] := 1 - 2 ArcCos[(1 - δ) Sin[2 π x]]/π; sqr[x_] := 2 ArcTan[Sin[2 π x]/δ]/π; swt[x_] := (1 + trg[(2 x - 1)/4] sqr[x/2])/2; Plot[{TriangleWave[x], trg[x]}, {x, -2, 2}, PlotRange -> All] Plot[{SquareWave[x], sqr[x]}, {x, -2, 2}, PlotRange -> All, Exclusions -> None] Plot[{SawtoothWave[x], ...

8

How about writing the Gram-Schmit down by yourself? GramSchmidt[w_?MatrixQ] := Module[{v = ConstantArray[0, Length[w]]}, Table[ v[[n]] = w[[n]] - Sum[(v[[i]].w[[n]]/v[[i]].v[[i]])*v[[i]], {i, 1, n - 1}], {n, 1, Length[w]}]; v ] Then you have the unscaled orthogonal basis GramSchmidt[{{1, 1, 1}, {1, 1/2, 1/3}, {1, 2, 3}}] ...

8

I'd go with the BinLists method. Were that not available, one could do well with a zero-order interpolation. These can be useful if the fence list is large, because lookup is efficient (log(n) rather than n). I do some negating to get the continuity to be at the left end of the intervals. interp[x_List] := With[{newx = Join[{-10^8}, x, {10^8}]}, ...

8

You can specify the evaluation of which construct should be stopped by Return by providing the second argument (undocumented?). For example, Scan[Function[x, Module[{}, Print[x]; Return[$Failed, Module]; Print[-x]]], {1, 2, 3}] or Scan[Function[x, Print[x]; Return[$Failed, CompoundExpression]; Print[-x]], {1, 2, 3}]

7

It's hard to reply without larger context, but if you are not restricted to use pure functions, then one option would be to use the pattern-defined overloaded function instead: ClearAll[fun]; fun[2] := Null; fun[x_] := ((*Do something useful*)Print[x]) Then, you just write: Scan[Function[x, Scan[fun, x]], {{1, 2, 3}, {4, 5, 6}}] In fact, you can as ...

7

As belisarius has shown(and I have voted for his answer) RegionPlot3D allows you to plot your region. FYI: Your lists of coordinates (as with all lists in Mathematica): coord = {{1, 0, 1}, {2, 0, 1}, {1, 0, 2}, {2, 0, 2}, {1, Pi/6, 1}, {2, Pi/6, 1}, {1, Pi/6, 2}, {2, Pi/6, 2}}; You can transform these cylindrical coordinates to cartesian coordinates: ...

7

I can see the source of your confusion: If you use Head[f[x]] and Head[5] you get f and Integer respectively. Then, you read the documentation Apply[f,expr] or f@@expr replaces the head of expr by f. and you expect Cos@@5 to replace the Integer head by Cos. The way I explain it to myself is by saying Mathematica has two (types of) heads ;-) One type is ...

7

One approach is to convolve the sawtooth wave directly with a Gaussian kernel. Since this can be done analytically, it is possible to return a function that is in closed form and hence can be differentiated without interpolation. f = Integrate[SawtoothWave[t/10] Exp[-3 (t - x)^2] , {t, 0, 50}] Plot[f, {x, 0, 50}] You can control the amount of "rounding" ...

7

The possibility to insert operators and functions as you know them from mathematics is not possible for all things. Usually, you find the special input possibilities on the reference page of the function in the Details section. See for instance the documentation of Integrate. For Binomial there seems to be no such 2d input, because as you already found out, ...

6

I like to think about @@ as a Frankstein decapitation operator. It take out the Head of the old expression and replace by the new one. And @@@ as a mass Frankstein decapitation operator. It get inside each list element and apply @@ to each element inside the list. To understand what Head means, use FullForm. For example, in the list l={1,2,3} if you apply ...

6

You could integrate over the region, using Boole: Integrate[ Boole[0 < p < 1 && 0 < e1 < 1/2 && 0 < e2 < 1/2 && (p < e1 || (p) (e1)/((p) (e1) + (1 - p) (1 - e2)) < e1/e2)], {p, 0, 1}, {e1, 0, 1/2}, {e2, 0, 1/2}] (* 1/16 (5 - 6 Log[2] + 2 Log[4]) *)

6

I have found this solution: In[1]:= f[x_] := CellPrint[{ Cell[BoxData[ToBoxes[x + 1]], "Output"], Cell[BoxData[ToBoxes[x + 2]], "Output"]}] In[2]:= f[2] 3 4 I was originally trying to achieve something like this: f[data_] := CellPrint[{ Cell["Data", "Subsection"], ...

5

Just to get you started RegionPlot3D[ 0 < z < 1 && 1 < Norm[{x, y}] < 2 && 1/2 < ArcTan[y, x] < 1.1, {x, 0, 3}, {y, 0, 3}, {z, -1, 2}, PlotPoints -> 100, Mesh -> False, PlotStyle -> Directive[Opacity[.3], Yellow]]

5

Here's something I use in class to demonstrate cylindrical coordinates (sorry for the length, but it's what I have :): Manipulate[ With[{$θColor = Red,$rColor = Darker[Blue], $zColor = Brown}, figure[P0_, 0., 0., 0.] := { Thick,$rColor, Line[{{0, 0, 0}, {P0[[1]], P0[[2]], 0}}], $zColor, Line[{{P0[[1]], P0[[2]], 0}, P0}] }; figure[P0_, ... 5 One part of your question is about iteration. Building on Yves comment, one good way is to pack everything inside a function. To simplify your problem, say the function is: f := RandomReal[{0, 1}]; Each time f is called, you get a new random number. (This greatly simplifies your problem, but the same idea holds.) Now to iterate 1000 times, you can use Map ... 5 Actually, your two results only differ by a constant of$\pm\sqrt2$. This is perfectly OK as you are dealing with indefinite integration. Try: Integrate[1/(r^2 Sqrt[x/r^(4 - 2 \[Gamma]) + 1]), r]; a = FullSimplify[% /. {x -> 2, \[Gamma] -> 3}] b = Integrate[1/(r^2 Sqrt[2/r^(4 - 6) + 1]), r] Assuming[r \[Element] Reals, FullSimplify[a - b]] 5 You can try this! fences = {1, 5, 9, 14}; vals = {-1, 1, 3, 4, 6, 9, 10, 13, 14, 15}; Select[vals, #] & /@ (Function[{x}, #1 <= x < #2] & @@@Partition[fences, 2, 1, {2, 1}, {Infinity, -Infinity}]) {{-1}, {1, 3, 4}, {6}, {9, 10, 13}, {14, 15}} 5 This is probably not going to be the best answer but offering it as an opener or as a guide to towards a better solution Setting your initial input as a function f[n_]:=Length[Select[IntegerPartitions[10],First[#]==n&]] then Map[f,Range[10]] {1, 5, 8, 9, 7, 5, 3, 2, 1, 1} No doubt regular contributors can improve on this 4 Here's another way using SplitBy fences = {1, 5, 9, 14}; values = {-1, 1, 3, 4, 6, 9, 10, 13, 14, 15}; Then: SplitBy[values, Function[{z}, #1 <= z < #2] & @@@ Partition[fences, 2, 1]] // Flatten[#, Length[fences] - 2] & Which gives: {{-1}, {1, 3, 4}, {6}, {9, 10, 13}, {14, 15}} 4 Assuming there is a Method other than "AllTours" that doesn't break if one point doesn't obey the triangle inequality, introduce a special point that has a distance 0 to all other points: points = {{-0.9, -0.89}, {.99, .97}, {0.1, .0}, magicPoint}; d[args__] /; FreeQ[{args}, magicPoint] := EuclideanDistance[args] d[__] = 0; FindShortestTour[points, ... 4 You could use table... unless I am missing something really basic. Speed, maybe? Edited to consider the special case as suggested by Kuba. linspace[start_, stop_, n_:100] := Table[x, {x, start, stop, (stop - start)/(n - 1)}] linspace[start_, stop_, 1] := Mean[{start,stop}] 4 The only method I can think of that will use the built-in simplification routines is to snoop on transformations using either TransformationFunctions or ComplexityFunction. Unfortunately neither of these will be restricted to the entire expression therefore what is produced may not be usable. Nevertheless as an example: FullSimplify[Gamma[1 - x] Gamma[x] ... 4 Maybe TimeConstraint is helpful: y = Gamma[1 - x] Gamma[x] Sin[Pi x] + Gamma[x] Gamma[1 - x] Sin[Pi (1 - x)]; FullSimplify[y, TimeConstraint -> 0.000001] FullSimplify[y, TimeConstraint -> 0.0001] FullSimplify[y, TimeConstraint -> 0.01] Gamma[1 - x] Gamma[x] Sin[π (1 - x)] + Gamma[1 - x] Gamma[x] Sin[π x] 2 Gamma[1 - x] Gamma[x] Sin[π x] 2 π 3 EDIT My previous answer related to the title of the question and was directed to "reaping" or "catching" first cases of a condition being met from a loop. The Euler formula, as I now understand, was a method for generating consecutive prime numbers :$n^2+n+k$, where$k$is prime and$n$ranges from 0 to$k-2\$. With all due respect this does not appear ...

3

You use #[[i]]&/@somelist a lot when instead you can use a part specification like: somelist[[All, i]] to get the i-th column. To count miss-classified you can look at the difference of the lists and count all non-zero elements like: Length[Select[Table[sig[[i]] != datasig[[i]], {i, 100}], # == True &]] (* Same as: *) Total@Unitize[sig - datasig] ...

3

I usually set up a wrapper function that transforms if input is valid and otherwise acts like Identity: pickyTransform[expr_] := 0 helper[expr_] /; ! AtomQ[expr] && FreeQ[expr, _?NumericQ] := pickyTransform[expr] helper[expr_] := expr FullSimplify[a^3 + x^y, TransformationFunctions -> {helper}] (* a^3 *) This works fine most of the time, but ...

3

You do not have to define a function to plot it. You can certainly do a=1; f:=a+x; Plot[f,{x,0,10}] and the output is the graph you expected. Defining the function as above has many drawbacks: 1) You cannot evaluate it without making an explicit replacement. For example, f(2) becomes f/.x->2 I would generalize this point and say that defining ...

3

There are as usual several ways. The most convenient one is probably MemberQ, as already pointed out in the comments. MemberQ[{1, 2, 3, 4, 9}, 9] (* True *) If you have a complex structure and not only a flat list, then FreeQ can be of use. Note that you have to negate the result. MemberQ[{1, 2, {3}, {{4, 9}}}, 9] Not[FreeQ[{1, 2, {3}, {{4, 9}}}, 9]] (* ...

3

Your equations don't seem to be consistent. y = E^-9.25 0.0000961117 c = 10.^-14 - y -0.0000961117 x = c y/5.7 10.^10 -16.2061 z = 276/x^2 1.05088 a = (x + c)/2 - z -9.15396 b = x + y - 2 z - a -9.15377 However, a b /z 79.7359 while your remaining equation states 9.8x10^-13 = [(b)(a)]/(z)

Only top voted, non community-wiki answers of a minimum length are eligible