In this presentation I show you how to read an electric meter. It is a very easy procedure, just like reading a clock, but there are several dials, some clockwise and some others counterclockwise.
For more information, codes and details, visit:
http://matrixlab-examples.com/tower-of-hanoi-algorithm.html
In this demonstration we’ll use 4 disks. The objective of the puzzle is to move all of the disks from tower A to tower C.
- -
Two Easy Rules:
Only one disk can be moved at a time and it can only be the top disk of any tower.
Disks cannot be stacked on top of smaller disks.
- -
We’re going to solve the puzzle by using recursion.
Recursion is a computer programming technique that involves the use of a procedure that calls itself one or several times until a specified condition is met.
- -
If we want to move disk 4 from A to C, after several moves and at some point, we MUST be in this situation:
And now, we can accomplish our first goal: move the largest disk to its final destination.
But now, if we ignore tower C, we are just like we were at the beginning, but with just 3 disks left (instead of 4)! We’ve simplified the puzzle!
If we want to move disk 3 from B to C, after several moves and at some point, we MUST be in this situation:
And now, we can accomplish our second goal: move the second largest disk to its final destination.
Now, the position is trivial to finish… but we still can repeat the ideas above.
- -
Let’s code that with recursion. We’ll call our function m (for move) and we’ll have four input parameters:
m(n, init, temp, fin)
where
n is the number of disks to move
init is the initial tower
temp is the temporary peg
fin is the final tower
We have three situations to consider:
1.- m(n-1, init, fin, temp)
we’ll move n-1 disks from A to B, with C as temporary peg.
2.- m(1, init, temp, fin)
we’ll move 1 disk (our partial goal) from A to C, with B as temporary peg.
3.- m(n-1, temp, init, fin)
we’ll move n-1 disks from B to C, with A as temporary peg.
If you'd like to use an online calculator for straight lines, go to:
http://matrixlab-examples.com/equation-of-a-straight-line.html
I'm gonna show you how to express the point-slope form for straight lines.
If you know that the slope of a line is m and also know any point (x1, y1)
Then, the point-slope equation of that line is y - y1 = m (x -- x1)
In this example, if we have a slope of -3 and the point (1, 1) then, our point-slope equation is y minus 1 equals -3 times x minus 1
y - 1 = -3 (x -- 1)
In this other example, if we have points (0, 5), (-2, 1)
we can calculate the slope and discover that it's 2.
m = (5 - 1) / (0 + 2) = 2
Using one point we get the equation: y - 5 = 2x
and using ghe other point we get another expression of the same line: y - 1 = 2(x + 2)
In this last example we have two point that allow us to calculate the slope: m = 6/2 = 3
and use the two given points to find our needed equation
Point-slope form 1: y - 7 = 3x
Point-slope form 2: y - 1 = 3(x + 2)
Thank you for watching!
For more details and examples, visit: http://www.matrixlab-examples.com/break-statement.html
Break and Continue Statements. Concepts, examples and code in Matlab.
The break statement terminates the execution of a for or while loop. Statements in the loop after the break statement do not execute. In nested loops, break exits only from the loop in which it occurs. Control passes to the statement that follows the end of that loop.
The continue statement temporarily interrupts the execution of a program loop, skipping any remaining statements in the body of the loop for the current pass. It continues within the loop for as long as the stated for or while condition holds true.
More examples on how to control the flow of the code: http://matrixlab-examples.com/matlab-code-3.html