I was doing image processing to determine the distance between two points in a picture. it involves a fair amount of geometry. One of the problems which I tried to solve using basic geometry but failed to arrive at a solution is the following. I have transformed the question into mathematical terms so that a wider audience could answer it.
The sides a, b, c, and the angle alpha are given. The length x is to be found
Using sine and cosine laws I`ve found:
Using Cosine Law and,
Using Sine Law
where beta is the angle opposite the side b
This is not a trivial problem, and maybe it should have been asked Math.SE.
But here is my take:
Considering the triangle abx
b^2 = x^2 + a^2 - 2*a*x*cos(β) #1
And the triangle a1cx
c^2 = x^2 + a1^2 -2*a1*x*cos(β) #2
sin(α)/α1 = sin(β)/c #3
Three non-linear equations to be solved for x, a1 and β.
Subtract #2 from #1 to eliminate x^2 (with some simplifications)
b^2 - c^2 = -2*x *(a-a1)*cos(β)+a^2 -a1^2 #4
use #3 to eliminate β in terms of a1 in #4
b^2 - c^2 = -2*x*(a-a1)*sqrt(1 - c^2/a1^2*sin(α)^2)+a^2-a1^2 #5
Now subtract (a/a1)*#2 from #1 to eliminate a1^2
b^2 - a*c^2/a1 = -(a-a1)*(x^2-a*a1)/a1 #6
Equations #5 and #6 are two non-linear equations to be solved for x and a1.
From #5 we have x in terms of a1 with
x = a1*(a^2-a1^2-b^2+c^2)/(2*(a-a1)*sqrt(a1^2-c^2*sin(α)^2)) #7
Unfortunately using the above in #6 results in a sixth order polynomial to be solved for a1.
It can only be solved numerically at this point. If a1 is found, then #7 also gives us x.
0 = 4*a^2*c^2*g^2
+ a1*(4*a*g^2*(a^2-b^2-c^2))
+ a1^2*(a^4-2a^2(b^2+c^2+4g^2)+b^4+2b^2(2g^2-c^2)+c^4)
+ a1^3*(-4a(a^2-b^2-c^2-g^2))
+ a1^4*(2(3a^2-b^2-c^2))
+ a1^5*(-4*a)
+ a1^6
where g = c*sin(α)
Related
I am trying to find GCD of the following polynomials ( two separate questions ) in Field modulo 2 and field modulo 3. But I am stuck in the first one for some reasons.
a(x) =x5+x3+x2+ 1,
b(x) =x3+x for mod 2
a(x) = 2x3+2x2+x+1
b(x) =x2+2 for mod 3
For the first one, I tried to represent the polynomials as bits of 1's and 0's (e.g : 101101 and 1010) and tried to find GCD using Euclid's algorithm, but at some point it leads to zero, which is not possible if I am doing the calculation correctly.
2nd set of polynomials, I am not sure at all, as it as co efficients more than 1.
Any help would be much appreciated.
Let
f_1 = x^5 + x^3 + x^2 + 1 and
f_2 = x^3 + x
Working mod 2 we can change the notation to
f_1 = (1,0,1,1,0,1) and
f_2 = (1,0,1,0).
Doing long division we get that
f_1 = q_2 * f_2 + f_3 where f_3 is of degree strictly less than the degree of f_2.
It turns out that
q_2 = (1,0,0) that is q_2 = x^2
f_3 = (1,0,1) that is f_3 = x^2 + 1
Continuing we get
f_2 = q_3 * f_3 + f_4
It turns out that
q_3 = (1,0) and
f_4 = (0)
That latter signals that Euclid's algorithm is done and the last non-zero polynomial among the f_n's is the GCD. Thus f_3 is the GCD. It is straight forward to show that f_3 is indeed a common divisor.
For the second case you work with tuples, like the (1,0,1) above, but this time the coordinates are 0, 1 or 2 (the remainders mod 3). Otherwise the algorithm is identical.
It would increase your understanding if you implemented your algorithm in some programming language.
I have a linear scale that ranges form 0.1 to 10 with increments of change at 0.1:
|----------[]----------|
0.1 5.0 10
However, the output really needs to be:
|----------[]----------|
0.1 1.0 10 (logarithmic scale)
I'm trying to figure out the formula needed to convert the 5 (for example) to 1.0.
Consequently, if the dial was shifted halfway between 1.0 and 10 (real value on linear scale being 7.5), what would the resulting logarithmic value be? Been thinking about this for hours, but I have not worked with this type of math in quite a few years, so I am really lost. I understand the basic concept of log10X = 10y, but that's pretty much it.
The psuedo-value of 5.0 would become 10 (or 101) while the psuedo-value of 10 would be 1010. So how to figure the pseudo-value and resulting logarithmic value of, let's say, the 7.5?
Let me know if addition information is needed.
Thanks for any help provided; this has beaten me.
Notation
As is the convention both in mathematics and programming, the "log" function is taken to be base-e. The "exp" function is the exponential function. Remember that these functions are inverses we take the functions as:
exp : ℝ → ℝ+, and
log : ℝ+ → ℝ.
Solution
You're just solving a simple equation here:
y = a exp bx
Solve for a and b passing through the points x=0.1, y=0.1 and x=10, y=10.
Observe that the ratio y1/y2 is given by:
y1/y2 = (a exp bx1) / (a exp bx2) = exp b(x1-x2)
Which allows you to solve for b
b = log (y1/y2) / (x1-x2)
The rest is easy.
b = log (10 / 0.1) / (10 - 0.1) = 20/99 log 10 ≈ 0.46516870565536284
a = y1 / exp bx1 ≈ 0.09545484566618341
More About Notation
In your career you will find people who use the convention that the log function uses base e, base 10, and even base 2. This does not mean that anybody is right or wrong. It is simply a notational convention and everybody is free to use the notational convention that they prefer.
The convention in both mathematics and computer programming is to use base e logarithm, and using base e simplifies notation in this case, which is why I chose it. It is not the same as the convention used by calculators such as the one provided by Google and your TI-84, but then again, calculators are for engineers, and engineers use different notation than mathematicians and programmers.
The following programming languages include a base-e log function in the standard library.
C log() (and C++, by inclusion)
Java Math.log()
JavaScript Math.log()
Python math.log() (including Numpy)
Fortran log()
C#, Math.Log()
R
Maxima (strictly speaking a CAS, not a language)
Scheme's log
Lisp's log
In fact, I cannot think of a single programming language where log() is anything other than the base-e logarithm. I'm sure such a programming language exists.
I realize this answer is six years too late, but it might help someone else.
Given a linear scale whose values range from x0 to x1, and a logarithmic scale whose values range from y0 to y1, the mapping between x and y (in either direction) is given by the relationship shown in equation 1:
x - x0 log(y) - log(y0)
------- = ----------------- (1)
x1 - x0 log(y1) - log(y0)
where,
x0 < x1
{ x | x0 <= x <= x1 }
y0 < y1
{ y | y0 <= y <= y1 }
y1/y0 != 1 ; i.e., log(y1) - log(y0) != 0
y0, y1, y != 0
EXAMPLE 1
The values on the linear x-axis range from 10 to 12, and the values on the logarithmic y-axis range from 300 to 3000. Given y=1000, what is x?
Rearranging equation 1 to solve for 'x' yields,
log(y) - log(y0)
x = (x1 - x0) * ----------------- + x0
log(y1) - log(y0)
log(1000) - log(300)
= (12 - 10) * -------------------- + 10
log(3000) - log(300)
≈ 11
EXAMPLE 2
Given the values in your question, the values on the linear x-axis range from 0.1 to 10, and the values on the logarithmic y-axis range from 0.1 to 10, and the log base is 10. Given x=7.5, what is y?
Rearranging equation 1 to solve for 'y' yields,
x - x0
log(y) = ------- * (log(y1) - log(y0)) + log(y0)
x1 - x0
/ x - x0 \
y = 10^| ------- * (log(y1) - log(y0)) + log(y0) |
\ x1 - x0 /
/ 7.5 - 0.1 \
= 10^| --------- * (log(10) - log(0.1)) + log(0.1) |
\ 10 - 0.1 /
/ 7.5 - 0.1 \
= 10^| --------- * (1 - (-1)) + (-1) |
\ 10 - 0.1 /
≈ 3.13
:: EDIT (11 Oct 2020) ::
For what it's worth, the number base 'n' can be any real-valued positive number. The examples above use logarithm base 10, but the logarithm base could be 2, 13, e, pi, etc. Here's a spreadsheet I created that performs the calculations for any real-valued positive number base. The "solution" cells are colored yellow and have thick borders. In these figures, I picked at random the logarithm base n=13—i.e., z = log13(y).
Figure 1. Spreadsheet values.
Figure 2. Spreadsheet formulas.
Figure 3. Mapping of X and Y values.
I'm new to R and I need to plot the quadratic matrix equation:
x^T A x + b^T x + c = 0
in R^2, with A being a 2x2, b a 2x1, and c a constant. The equation is for a boundary that defines classes of points. I need to plot that boundary for x0 = -6...6, x1 = -4...6. My first thought was generate a bunch of points and see where they are zero, but it depends on the increment between the numbers (most likely I'm not going guess what points are zero).
Is there a better way than just generating a bunch of points and seeing where it is zero or multiplying it out? Any help would be much appreciated,
Thank you.
Assuming you have a symmetric matrix A,
eg
# A = | a b/2 |
# | b/2 c |
and your equation represents a conic section, you can use the conics package
What you need is a vector of coefficients c(a,b,c,d,e,f) representing
a.x^2 + b*x*y + c*y^2 + d*x + e*y + f
In your case, say you have
A <- matrix(c(2,1,1,2))
B <- c(-20,-28)
C <- 10
# create the vector
v <- append(c(diag(A),B,C),A[lower.tri(A)]*2), 1)
conicPlot(v)
You could easily wrap the multiplication out into a simple function
# note this does no checking for symmetry or validity of arguments
expand.conic <- function(A, B, C){
append(c(diag(A),B,C),A[lower.tri(A)]*2), 1)
}
This question states:
A Pythagorean triplet is a set of three natural numbers, a b c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
I'm not sure what's it trying to ask you. Are we trying to find a2 + b2 = c2 and then plug those numbers into a + b + c = 1000?
You need to find the a, b, and c such that both a2 + b2 = c2 and a + b + c = 1000. Then you need to output the product a * b * c.
These problems are often solvable trivially, if you find the proper insight. The trick here is to use a little algebra before you ever write a loop. I'll give you one hint. Look at the formula to generate pythagorean triples. Can you write the sum of the side lengths in a useful way?
Like a large number of project euler problems, it's all about finding a set of numbers that simultaneously fulfil multiple constraints.
In this case, the constraints are:
1) a^2 + b^2 = c^2
2) a+b+c = 1000
In the early questions the solution can be as simple as nested loops which try each possible combination.
I was following this thread and copied the code in my project. Playing around with it turns out that it seems not to be very precise.
Recall the formula: y = ax^2 + bx +c
Since the first given point I have is at x1 = 0, we already have c=y1 . We just need to find a and b. Using:
y2 = ax2^2 + bx2 +c
y3 = ax3^2 + bx3 +c
Solving the equations for b yields:
b = y/x - ax - cx
Now setting both equations equal to each other so b falls out
y2/x2 - ax2 - cx2 = y3/x3 - ax3 - cx3
Now solving for a gives me:
a = ( x3*(y2 - c) + x2*(y3 - c) ) / ( x2*x3*(x2 - x3) )
(is that correct?!)
And then using again b = y2/x2 - ax2 - cx2 to find b. However so far I haven't found the correct a and b coeffs. What am I doing wrong?
Edit
Ok I figured out, but had to use a CAS because I don't know how to invert symbolic matrices by hand. (Gauss algo doesn't seem to work)
Writing it down in Matrix form:
| 0 0 1 | |a|
| x2^2 x2 1 | * |b| = Y
| x3^2 x3 1 | |c|
Let's call the Matrix M and multiply from the left with M^(-1)
|a|
|b| = M^(-1)*Y
|c|
Then I got out of maple:
a = (-y1 * x2 + y1 * x3 - y2 * x3 + y3 * x2) / x2 / x3 / (-x2 + x3)
Guess I did a stupid mistake somewhere above.
Which gives me the same result as the formula in the thread quoted above.
Your problem is that you have three unknowns (the coefficients a, b, and c) and only one equation that I can see: y = y1 when x = 0; this gives c = y1, as you said.
Without more information, all you can do is tell how b is related to a. That's it. There isn't one solution, there are many solutions.
If you're telling me that you have two other points (x2, y2) and (x3, y3), then you should substitute all of them into the equation and solve. Start with:
(source: equationsheet.com)
Now substitute the three points (x1, y1), (x2, y2), and (x3, y3):
(source: equationsheet.com)
This is the matrix equation that you need to invert. You can use Cramer's rule or LU decomposition. Another possibility is Wolfram Alpha:
http://www.wolframalpha.com/input/?i=inverse{{x1*x1,+x1,+1},+{x2*x2,+x2,+1},+{x3*x3,+x3,+1}}
Take the inverse that the link gives you and multiply the right hand side vector by it to solve for your three coefficients.
It's a pretty easy thing to code if you note that
det = (x2 x1^2-x3 x1^2-x2^2 x1+x3^2
x1-x2 x3^2+x2^2 x3)
Divide all the entries in the matrix by this value. The numerators are pretty simple:
(source: equationsheet.com)
Divide this by the determinant and you've got your inverse.
If you have more points than three you need to do a least squares fit. Do the same trick of substituting all the points you have (x1, y1)...(xn, yn). You'll have more equations than unknowns. Multiply both sides by the transpose of the nx3 matrix and solve. Voila - you'll have the set of coefficients that minimize the squares of errors between the points and the function values.