I am trying to simply enter the character "i" into SageMathCloud so that I can construct imaginary numbers, this is my syntax:
ran40 = matrix(QQ,2,2,[[2*i,-2],[3,4]])
show(ran40)
I am constructing a matrix so that I can compute the reduced-row echelon form. The first element that is 2*i just needs to be 2i but I keeping getting syntax errors, how do I enter i for an imaginary number into SageMathCloud? I cannot find an example anywhere on the internet, if anyone knows this syntax please do inform me.
Your problem is that you decided what the ring is, and that ring doesn't have any imaginaries.
matrix(QQ,2,2,[[2*i,-2],[3,4]])
QQ is the rationals (the fraction field of ZZ, if you like).
Is this what you want? It will make things in the "symbolic ring" which can be slow...
M = matrix(2,2,[[2*i,-2],[3,4]])
show(M)
show(M.echelon_form())
show(M.rref())
Related
This is probably straightforward, elementary and whatever, but I can't manage to get it. I have 2 Nx1vectors u and w, which are composed by both negative and positive values. I am trying to compute w'u u'w , which should be a quadratic form. I should be able to write this like
t(w)%*%u%*%t(u)%*%w
However sometimes I get a negative value, depending on the values in the two vectors. This is not possible, since that thing is a quadratic form. I tried with
crossprod(w, u)%*%crossprod(u, w)
and
crossprod(w, u)*crossprod(u, w)
which gives positive and equal results. However, since I am dealing with Nx1vectors, I should also be able to write it as
`sum(w*u)^2`
which gives a positive value but different from the ones above.
So I guess I am doing something wrong somewhere. So, the question is: how can I express w'u u'w which is valid for both vectors and matrices ?
EDIT: here a csv file with the original vectors to reproduce exactly the same issue
When i started reading about Qr Codes every article browsed i can see one QR Code Exponents of αx Table which having values for the specific powers of αx . I am not sure how this table is getting created. Can anybody explain me the logic behind this table.
For reference the table can be found at http://www.matchadesign.com/_blog/Matcha_Design_Blog/post/QR_Code_Demystified_-_Part_4/#
(The zxing source code for this might help you.)
It would take a lot to explain all the math here. For the Reed-Solomon error correction, you need a Galois field of 256 elements (nothing fancy -- just a set of 256 things that have addition and exponentiation and such defined.)
This is defined not in terms of numbers, but in terms of polynomials whose coefficients are all 0 or 1. We work with polynomials with 8 coefficient -- conveniently these map to 8-bit values. While it's tempting to think of those values as numbers, they're really something different.
In fact for addition and such to make sense such that all the operations land you back in a value in the Galois field, all the results are computed modulo an irreducible polynomial in the field. (Skip what that means now.)
To make operations faster, it helps to pre-compute what the powers of the polynomial "x" are in the field. This is alpha. You can think of this as "2", since the polynomial "x" is 00000010, though that's not entirely accurate.
So then you just compute the powers of x in the field. Because it's a field you'll hit every element of the field this way. The sequence seems to be the powers of two, which it happens to map to for a short while, until the first "modulo" of the primitive polynomial takes effect. Multiplying by x is indeed still something like multiplying by 2 but it's a bit of coincidence in this field, really.
This is over my head, can someone explain it to me better? http://mathworld.wolfram.com/Reflection.html
I'm making a 2d breakout fighting game, so I need the ball to be able to reflect when it hits a wall, paddle, or enemy (or a enemy hits it).
all their formula's are like: x_1^'-x_0=v-2(v·n^^)n^^.
And I can't fallow that. (What does ' mean or x_0? or ^^?)
The formula for reflection is easier to understand if you think to the geometric meaning of the operation of "dot product".
The dot product between two 3d vectors is mathematically defined as
<a, b> = ax*bx + ay*by + az*bz
but it has a nice geometric interpretation
The dot product between a and b is the length
of the projection of a over b taken with
a negative sign if the two vectors are pointing in
opposite directions, multiplied by the length of b.
Something that is immediately obvious using this definition and that it's not evident if you only look at the formula is for example that the dot product of two vectors doesn't change if the coordinate system is rotated, that the dot product of two perpendicular vectors is 0 (the length of the projection is clearly zero in this case) or that the dot product of a vector by itself is the square of its length.
Something that is instead less obvious using the geometric interpretation is that the dot product is commutative, i.e. that <a, b> = <b, a> (fact that is clear considering the formula).
An important point to consider is also that if the length of b is 1 then the dot product <a, b> is simply the length of the projection of a over b (taken with the proper sign).
Given this interpretation the formula for computing the reflection over a plane is quite easy to understand:
To compute the reflected vector r, given a vector a and a plane with normal n you just need to use the formula:
r = a - 2<a, n> n
the height h in the figure is in this case just <a, n> (note that n is assumed to be of unit length) and so it should be clear that you need to move twice that height in the direction of the normal.
If you consider the proper dot product signs you should see that the formula applies also when the incident vector a and the plane normal n are facing in the same direction.
The prime (') indicates the second form of a number/point/structure. In this case, x₁' refers to the reflected form of x₁.
The subscript (0) shows various states of the same. In this case, x₀ is the point of reflection.
The caret notation (^) shows that something is a vector. In this case, n̂ is the normal vector.
Is this just about the equation formatting? Because I see nicely formatted equations, not the LaTeX-style markup appearing in your question. So step 1: try viewing the page in a different web browser and see if it looks clearer.
More substantively, I'd recommend a different kind of resource. Fundamentally, you're looking at collisions, which are normally better treated in a physics text than a math text. Any introductory physics textbook will have a chapter on collisions, which should be directly applicable to your game.
I have question that comes from a algorithms book I'm reading and I am stumped on how to solve it (it's been a long time since I've done log or exponent math). The problem is as follows:
Suppose we are comparing implementations of insertion sort and merge sort on the same
machine. For inputs of size n, insertion sort runs in 8n^2 steps, while merge sort runs in 64n log n steps. For which values of n does insertion sort beat merge sort?
Log is base 2. I've started out trying to solve for equality, but get stuck around n = 8 log n.
I would like the answer to discuss how to solve this mathematically (brute force with excel not admissible sorry ;) ). Any links to the description of log math would be very helpful in my understanding your answer as well.
Thank you in advance!
http://www.wolframalpha.com/input/?i=solve%288+log%282%2Cn%29%3Dn%2Cn%29
(edited since old link stopped working)
Your best bet is to use Newton;s method.
http://en.wikipedia.org/wiki/Newton%27s_method
One technique to solving this would be to simply grab a graphing calculator and graph both functions (see the Wolfram link in another answer). Find the intersection that interests you (in case there are multiple intersections, as there are in your example).
In any case, there isn't a simple expression to solve n = 8 log₂ n (as far as I know). It may be simpler to rephrase the question as: "Find a zero of f(n) = n - 8 log₂ n". First, find a region containing the intersection you're interested in, and keep shrinking that region. For instance, suppose you know your target n is greater than 42, but less than 44. f(42) is less than 0, and f(44) is greater than 0. Try f(43). It's less than 0, so try 43.5. It's still less than 0, so try 43.75. It's greater than 0, so try 43.625. It's greater than 0, so keep going down, and so on. This technique is called binary search.
Sorry, that's just a variation of "brute force with excel" :-)
Edit:
For the fun of it, I made a spreadsheet that solves this problem with binary search: binary‑search.xls . The binary search logic is in the second data column, and I just auto-extended that.
Someone somewhere has had to solve this problem. I can find many a great website explaining this problem and how to solve it. While I'm sure they are well written and make sense to math whizzes, that isn't me. And while I might understand in a vague sort of way, I do not understand how to turn that math into a function that I can use.
So I beg of you, if you have a function that can do this, in any language, (sure even fortran or heck 6502 assembler) - please help me out.
prefer an analytical to iterative solution
EDIT: Meant to specify that its a cubic bezier I'm trying to work with.
What you're asking for is the inverse of the arc length function. So, given a curve B, you want a function Linv(len) that returns a t between 0 and 1 such that the arc length of the curve between 0 and t is len.
If you had this function your problem is really easy to solve. Let B(0) be the first point. To find the next point, you'd simply compute B(Linv(w)) where w is the "equal arclength" that you refer to. To get the next point, just evaluate B(Linv(2*w)) and so on, until Linv(n*w) becomes greater than 1.
I've had to deal with this problem recently. I've come up with, or come across a few solutions, none of which are satisfactory to me (but maybe they will be for you).
Now, this is a bit complicated, so let me just give you the link to the source code first:
http://icedtea.classpath.org/~dlila/webrevs/perfWebrev/webrev/raw_files/new/src/share/classes/sun/java2d/pisces/Dasher.java. What you want is in the LengthIterator class. You shouldn't have to look at any other parts of the file. There are a bunch of methods that are defined in another file. To get to them just cut out everything from /raw_files/ to the end of the URL. This is how you use it. Initialize the object on a curve. Then to get the parameter of a point with arc length L from the beginning of the curve just call next(L) (to get the actual point just evaluate your curve at this parameter, using deCasteljau's algorithm, or zneak's suggestion). Every subsequent call of next(x) moves you a distance of x along the curve compared to your last position. next returns a negative number when you run out of curve.
Explanation of code: so, I needed a t value such that B(0) to B(t) would have length LEN (where LEN is known). I simply flattened the curve. So, just subdivide the curve recursively until each curve is close enough to a line (you can test for this by comparing the length of the control polygon to the length of the line joining the end points). You can compute the length of this sub-curve as (controlPolyLength + endPointsSegmentLen)/2. Add all these lengths to an accumulator, and stop the recursion when the accumulator value is >= LEN. Now, call the last subcurve C and let [t0, t1] be its domain. You know that the t you want is t0 <= t < t1, and you know the length from B(0) to B(t0) - call this value L0t0. So, now you need to find a t such that C(0) to C(t) has length LEN-L0t0. This is exactly the problem we started with, but on a smaller scale. We could use recursion, but that would be horribly slow, so instead we just use the fact that C is a very flat curve. We pretend C is a line, and compute the point at t using P=C(0)+((LEN-L0t0)/length(C))*(C(1)-C(0)). This point doesn't actually lie on the curve because it is on the line C(0)->C(1), but it's very close to the point we want. So, we just solve Bx(t)=Px and By(t)=Py. This is just finding cubic roots, which has a closed source solution, but I just used Newton's method. Now we have the t we want, and we can just compute C(t), which is the actual point.
I should mention that a few months ago I skimmed through a paper that had another solution to this that found an approximation to the natural parameterization of the curve. The author has posted a link to it here: Equidistant points across Bezier curves