Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
I have an equation which I want to simplify in order to retrieve the solution. But the equation contains absolute in it. How can it be more simplified?
d = abs(X²-vs²)/2*a1 + abs(vf²-X²)/2*a2
abs is the absolute of the value inside the parenthesis
X is the unknown and we know d, vs, a1, vf and a2
So in the end the equation would be X = ....
A solution for this would be to solve the 4 following equations:
d = (X²-vs²)/2*a1 + (vf²-X²)/2*a2
d = (vs²-X²)/2*a1 + (vf²-X²)/2*a2
d = (X²-vs²)/2*a1 + (X²-vf²)/2*a2
d = (vs²-X²)/2*a1 + (X²-vf²)/2*a2
And then see which solutions are compatible with the initial equation.
The main idea is to rewrite the one abs(A) ... = 0 equation into 2 with conditions:
abs(A) ... = 0
is equal to
A ... = 0 when A >= 0
-A ... = 0 when A < 0
In your case we can turn then initial equation into three . Let's suppose that
vs**2 < vf**2
so we have 3 cases:
X <= vs so abs(X**2 - vs**2) = -(X**2 - vs**2) ; (vf**2 - X**2) = vf**2 - X**2
vs < X <= vf so abs(X**2 - vs**2) = X**2 - vs**2 ; (vf**2 - X**2) = vf**2 - X**2
vf < X so abs(X**2 - vs**2) = X**2 - vs**2 ; (vf**2 - X**2) = -(vf**2 - X**2)
Ans we have three easy to solve equations with conditions on X:
d = -(X**2 - vs**2) / 2 / a1 + (vf**2 - X**2)/2 * a2 when X <= vs
d = (X**2 - vs**2) / 2 / a1 + (vf**2 - X**2)/2 * a2 when vs < X <= vf
d = (X**2 - vs**2) / 2 / a1 - (vf**2 - X**2)/2 * a2 when vf < X
Solve all of them, but take X if and only if it met the condition. In case that vs**2 > vf**2 you have 3 a bit different conditions:
X <= vf
vf < X <= vs
vs < X
and equations will be
d = -(X**2 - vs**2) / 2 / a1 + (vf**2 - X**2)/2 * a2 when X <= vf
d = -(X**2 - vs**2) / 2 / a1 - (vf**2 - X**2)/2 * a2 when vs < X <= vf
d = (X**2 - vs**2) / 2 / a1 - (vf**2 - X**2)/2 * a2 when vf < X
By definition:
abs(x) = x if x >= 0, &
-x if x <=0
So turn this equation into 4 equations, for all combinations of each abs term positive or negative, i.e. + +, + -, - +, - -
Solve each of the four equations, and discard any solutions that don't satisfy the sign assumption about the abs term of that particular equation after you plug the answer back into the abs term. Any solutions remaining that do satisfy the abs sign assumption are the actual answers.
Related
X_hat is an approximation of X. It is given by the X_t, the truncation of X using t bits.
Find the limits of X_t / X.
X_hat and X_t are represented in floating-point binary.
From my understand:
If t = 3 and X_hat = 1, X_t = 1.01
1/1 = 1 is the upper limit? What about the lower limit?
The following assumes the question is about significant bits (for an example in decimal, 3141592 truncated to 3 significant digits would be 3140000, and truncated to 5 significant digits would be 3141500). Since the question is about the relative error, it does not matter whether or where there is a decimal point, so it can be assumed without loss of generality that the numbers are integers.
If X = 0 then X̂ = X = 0 and X̂ / X is undefined.
Otherwise, if 0 < X < 2^(t-1) then X has at most t-1 significant bits, and truncation leaves X unchanged, so X̂ = X and X̂ / X = 1.
Otherwise, if X >= 2^(t-1) then X can be written as X = 2^n q + r where n >= 0, 2^(t-1) <= q < 2^t and 0 <= r < 2^n. The leftmost t bits of X are q, so the truncation of X to t significant bits is X̂ = 2^n q.
Then X̂ / X = 2^n q / (2^n q + r) = 1 - 1 / (1 + r / (2^n q)). The expression is decreasing in r and increasing in q, which combined with r < 2^n and q >= 2^(t-1) gives the lower bound:
X̂ / X > 2^(n+t-1) / (2^(n+t-1) + 2^n)
= 1 - 1 / (1 + 2^(t-1))
For a fixed n > 0 the exact lower bound derived from r <= 2^n - 1 and q >= 2^(t-1) is:
X̂ / X >= 2^(n+t-1) / (2^(n+t-1) + 2^n - 1)
= 1 - (2^n - 1) / (2^(n+t-1) + 2^n - 1)
= 1 - 1 / (1 + 2^(n+t-1) / (2^n - 1))
= 1 - 1 / (1 + 2^(t-1) / (1 - 1 / 2^n))
This lower bound is attained for X = 2^(n+t-1) + 2^n - 1 corresponding to X̂ = 2^(n+t-1). In the limit n → ∞ it reduces to the lower bound independent of n derived at the previous step.
I want to calculate the sum of the series as below
Lim
X->1 (2/3 - x/3 -(x^2)/3 +(x^3)*2/3 -..). I am not sure whether we have a formula for finding the sum of this kind of series. Tried a lot but couldn't find any. Any help is appreciated.
This seems to be more maths than computing.
It factorises as (1 + x^3 + x^6 + ...)(2 - x - x^2)/3
If x = 1-d (where d is small), then to first order in d, the (2 - x - x^2) term becomes (2 - (1-d) - (1-2d)) = 3d
And the (1 + x^3 + x^6 + ...) term is a geometric progression, with sum 1/(1-x^3), or here 1/(1-(1-d)^3), and the denominator to first order in d is (1 - (1-3d)) = 3d
Hence the whole thing is (1/3d) (3d) / 3 = 1/3
But we can also verify computationally with a value close to 1 (Python code here):
x = 0.999999
s = 0
f = (2 - x - x*x) / 3.
x3 = x ** 3
s_prev = None
while s != s_prev:
s_prev = s
s += f
f *= x3
print(s)
gives:
0.33333355556918565
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
suppose i want to find any value of x and y such that they satisfy x . W + y . D = P
this can be done by the following using extended euclidean algorithm
int exgcd(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int g, xi, yi;
g = exgcd(b, a % b, xi, yi);
x = yi;
y = xi - (a / b * yi);
return g;
}
but this will be just some random x and y satisfying the equation
suppose i add an additional constraint that i want any x y z such that
x>=0 y>=0 z>=0 and x + y + z = n
how can i effectively (please share code/pseudocode if possible) find all such x y and z??
my question boils down to find any x and y (using extended euclidean algorithm) which
1) satisfy a linear equation
2) fall in a given range
here is the link to the question if you want
Ok so we have 2 equations and 3 unknowns, so doing some simple mathematics we can find the equations we need to solve
x * W + y * D + z * 0 = p
And
x + y + z = n
given
x,y,z >=0
So firstly we will reduce one unknown by looping through any one of the unknowns lets say z
We iterate through 0 - n for z and our new equations will be
x * w + y * d = p
And
x + y = m { m is n - z for value of z in current iteration
Now we have 2 equations and 2 unknowns
So our solution for x and y can now be reduced by substituting x in first equation
Which makes it
(m - y) * w + y * d = p
This can be reduced to
y = (p - m * w) / (d - w)
and
x = m - y
You can stop at first value where x and y are integers
I am not sure whether this is right place to ask. Here N, L, H, p, and d are parameters. I need to solve this system of equations. Specifically, I need to solve for b(t) and e(t).
Variables | t=1 | t>1
----------|--------|------------------------
n(t) | N |N(1-p)^(t-1)
s(t) | 1 |((1-p+dp)/(1-p))^(t-1)
b(t) | L |b(t-1)+p(H-b(t-1))
e(t) |(H-L)/2 |e(t-1)+(p(H-b(t-1)))/2
c(t) |(1-d)pN |(1-d)pN(1-p+dp)^(t-1)
Please help me how should I start this problem to solve.
Since you used a Wolfram-Mathematica tag, perhaps you intend to use Mathematica
RSolve[{b[1]==L, b[t]==b[t-1]+p(H-b[t-1]),
e[1]==(H-L)/2, e[t]==e[t-1]+p(H-b[t-1])/2}, {b[t],e[t]}, t]//FullSimplify
which returns
Solve::svars: Equations may not give solutions for all "solve" variables
{b[t]->H+(-H+L)(1-p)^(-1+t),
e[t]->((H-L)(-2+(1-p)^t+2 p))/(2(-1+p))}
It seems that these formulas give recurrent equations - you find values for t = 1 (from table), then calculate values for t = 2, then for t = 3 and so on
b(t) = b(t-1) + p * (H - b(t-1))
t = 1: L
t = 2: b(2) = b(1) + p * (H - b(1)) or
L + p * (H - L) = L + p * H - p * L
t = 3: b(3) = b(2) + p * (H - b(2))
Example: L= 2; p = 3; H = 7;
b(1) = 2
b(2) = 2 + 3 * (7 - 2) = 17
b(3) = 17 + 3 * (7 - 17) = -13
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I don't really know if what I want to do is considered interpolation but I'll try to explain.
Now when I want to go from point A to point B(for simplicity consider only 1 coordinate space) in time T I compute position using linear interpolation formula:
P(t) = A + (B-A) * (t / T), T != 0
This works fine in most cases, but I want to cosider acceleration and braking like this:
first x% of the time it will be acceleration from vi speed to v speed
next y% of the time it will be constant v speed
last z% of the time it will be deceleration to reach vf speed at t = T
How can I compute P(t), t in [0, T] considering acceleration and braking?
Consider we have the following points in time:
t0 = 0 is the beginning of the movement
ta is the point when acceleration ends
td is the point when decceleration begins
T is the end of the movement
Then we have three segments of the movement. [t0, ta], (ta, td], (td, T]. Each can be specified separately. For the acceleration / decceleration we need to calculate the acceleration aa and the decceleration ad as follows:
aa = (v - vi) / (ta - t0)
ad = (vf - v) / (T - td)
According to your question, all values are given.
Then the movement can be expressed as:
P(t) :=
if(t < ta)
1 / 2 * aa * t^2 + vi * t + A
else if(t < td)
v * (t - ta) + 1 / 2 * aa * ta^2 + vi * ta + A
// this is the length of the first part
else
1 / 2 * ad * (t - td)^2 + v * (t - td)
+ v * (td - ta) + 1 / 2 * aa * ta^2 + vi * ta + A
//those are the lengths of the first two parts
If we precompute the lengths of the parts as
s1 := 1 / 2 * aa * ta^2 + vi * ta + A
s2 := v * (td - ta)
then the formula becomes a bit shorter:
P(t) :=
if(t < ta)
1 / 2 * aa * t^2 + vi * t + A
else if(t < td)
v * (t - ta) + s1
else
1 / 2 * ad * (t - td)^2 + v * (t - td) + s1 + s2
Here is an example plot:
However, it is very likely that the movement does not hit B at T except you chose proper values. That is because the equation is over-specified. You can e.g. calculate v based on B instead of specifying it.
Edit
The calculation of v to reach a specific B is:
v = (2 * A - 2 * B - td * vf + T * vf + ta * vi) / (ta - td - T)