Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Evaluate
(z x^-1 y)^5 y^5
~~~~~~~~~~~~~~~~~~~~~~~ OVER
x^-4 z^-4
How would I evaluate this if X = 10, y = -3 and z = 3? I would like a step-by-step solution to help me fully understand it.
Numerator evaluates as (z*y*x^-1)^5 * y^5
further rewriting ((z^5*y^5)*y^5)/x^5
Denominator ((1/x^4)*(1/z^4))
Final Answer would be ((y^10)*(z^9))/x
as per your values it (3^19)/10
Exponentials have higher priority in most computer languages, so adding parentheses like this should make it clearer. I'm assuming that you're dividing the first polynomial by the second. It's simple algebra.
(z x^-1 y)^5 y^5
---------------- =
x^-4 z^-4
(y^10)(z^9)/x
You substitute the numbers.
Start with:
((z * x^-1 * y)^5 * y^5)/(x^-4 * z^-4)
Commute the exponent to the z factor: (A * B)^N => A^N * B^N
(z^5 * (x^-1 * y)^5 * y^5)/(x^-4 * z^-4)
Commute the exponent to the x and y factors: (A * B)^N => A^N * B^N
(z^5 * (x^-1)^5 * y^5 * y^5)/(x^-4 * z^-4)
Simplify the exponenet on the x factor: (A^N)^M => A^(N*M)
(z^5 * x^-5 * y^5 * y^5)/(x^-4 * z^-4)
Combine the y factors: A^N * A^M => A^(N+M)
(z^5 * x^-5 * y^10)/(x^-4 * z^-4)
Remove the negative exponent on x: 1/A^-N => A^N
(z^5 * x^-5 * y^10 * x^4) / (z^-4)
Remove the negative exponenet on z: 1/A^-N => A^N
z^5 * x^-5 * y^10 * x^4 * z^4
Combine the z factors: A^N * A^M => A^(N+M)
z^9 * x^-5 * y^10 * x^4
Combine the x factors: A^N * A^M => A^(N+M)
z^9 * x^-1 * y^10
Remove the negative exponent on x: A^(-N) => 1/A^N
(z^9 * y^10)/(x^1)
Simplify the x factor: A^1 => A
(z^9 * y^10)/(x)
And that's the algebraic form of your answer.
Next, subsitute the values:
3^9 * (-3)^10 / 10
Factor the exponents:
(3^3)^3 * (-3)^10 / 10
(3^3)^3 * ((-3)^2)^5 / 10
Evalutate the innermost exponents:
(3 * 3 * 3)^3 * ((-3)^2)^5 / 10
(9 * 3)^3 * ((-3)^2)^5 / 10
27^3 * ((-3)^2)^5 / 10
27^3 * 9^5 / 10
Continue evaluation exponents, breaking them down for simplicity:
27 * 27 * 27 * 9^5 / 10
27 * 27 * 27 * 9^5 / 10
729 * 27 * 9^5 / 10
19683 * 9^5 / 10
19683 * 9^2 * 9^2 * 9 / 10
19683 * 81 * 81 * 9 / 10
Then multiply the factors:
19683 * 81 * 729 / 10
19683 * 59049 / 10
1162261467 / 10
116226146.7
And there's your final answer.
You could also take advantage of the fact that X^N = (-X)^N if N is even by replacing -3 with 3 since 10 is even.
3^9 * (-3)^10 / 10
3^9 * 3^10 / 10
3^19 / 10
3 * 3^18 / 10
3 * (3^9)^2 / 10
3 * (3 * 3^8)^2 / 10
3 * (3 * (3^2)^4)^2 / 10
3 * (3 * ((3^2)^2)^2)^2 / 10
3 * (3 * (9^2)^2)^2 / 10
3 * (3 * 81^2)^2 / 10
3 * (3 * 6561)^2 / 10
3 * (19683)^2 / 10
3 * 387420489 / 10
1162261467 / 10
116226146.7
Related
Design a recursive algorithm f(n1, n2, delta) that multiplies specific natural numbers between n1
and n2 (n1 > n2) as follows.
Starting with n1 multiply all natural numbers with a distance of delta from the previous natural
number.
Example: n1 = 35, n2 = 15, delta = 5
f(35, 15, 5) = 35 * 30 * 25 * 20 * 15
Solution:
Input: n1, n2 ∈ ℕ, n1 > n2, ∃ x ∈ ℕ: n2 + (x * delta) = n2
Output: n1 * (n1 - delta ) * (n1 – 2 * delta) * … * n2
f(n2, n2, delta) = n2
f(n1, n2, delta) = n1 * f((n1-delta), n2, delta)
Can someone explain this solution?
This solution implies a recursive algorithm (pseudo-code below). The idea in the solution is that you can "diminish" the problem by decreasing n1 by delta, and the stopping condition is that n1 is smaller than n2.
Note that the explanation you mentioned is a bit inaccurate as it does assumes that after some steps n2 is gotten, while you may reach some value < n2 (for example, if you change the 15 in the call f(35,15,5) to 14).
The pseudo-code:
f(n1, n2, delta):
if n1 < n2:
return 1
return n1 * f(n1 - delta, n2, delta)
Running example on your case (f(n1) instead of f(n1,n2,delta) is used for brevity as only n1 is changes):
f(35) = 35 * f(30) =
35 * 30 * f(25) =
35 * 30 * 25 * f(20) =
35 * 30 * 25 * 20 * f(15) =
35 * 30 * 25 * 20 * 15 * f(10) =
35 * 30 * 25 * 20 * 15 * 1
I've taken a few measurements of an LC circuit and I need to solve for both L and C based on that. How do I solve this?
2.675e6 = 1 / (2 * pi * sqrt(L * (C + 100e-9))
5.8e6 = 1 / (2 * pi * sqrt(L * C))
You need pencil and paper:
Equation #1
5.8e6 = 1 / (2 * pi * sqrt(L * C))
sqrt(L * C)= 1 / (2 * pi * 5.8e6 )
L*C = 1 / (2 * pi * 5.8e6 )^2
Equation #2
2.675e6 = 1 / (2 * pi * sqrt(L * (C + 100e-9))
sqrt(L * (C + 100e-9))= 1 / ( 2 *pi *2.675e6 )
L * (C + 100e-9) = 1 / ( 2 *pi *2.675e6 )^2
Subtract #1 from #2
L * (C + 100e-9) - L*C = 1 / ( 2 *pi *2.675e6)^2 - 1 / (2 * pi * 5.8e6 )^2
L * 100e-9 = 1 / ( 2 *pi *2.675e6)^2 - 1 / (2 * pi * 5.8e6 )^2
L = 1e7 * (1 / ( 2 *pi *2.675e6)^2 - 1 / (2 * pi * 5.8e6 )^2 )
and than from #1
C = ( 1 / (2 * pi * 5.8e6 )^2 ) / L
at the moment I am writing my bachelor thesis and I have to program in R for the first time. I think not the best way to learn R but never mind.
My question is concerning a function that can solve an equation like this:
q <- function(ytc) {
(5 / ((1 + (ytc / 4))^4 * ((1645 * 5 / 1826) - (1640 * 5 / 1826)))) +
(5 / ((1 + (ytc / 4))^4 * ((1736 * 5 / 1826) - (1640 * 5 / 1826)))) +
(5 / ((1 + (ytc / 4))^4 * ((1826 * 5 / 1826) - (1640 * 5 / 1826)))) +
100 / (((1 + (ytc / 4))^4 * ((1826 * 5 / 1826) - (1640 * 5 / 1826)))) - 100
}
My aim is to simply solve for the ytc what should be the yield to call of a bond. But I cannot find any way to figure it out. This should be a simple PV calculation like: PV=c/(1+r/4)^4*t1+c/(1+r/4)^4*t2+.... and hence solve vor r. But don't know how to do that. I tried several functions like uniroot, unroot.all, ... but nothing could figure out the solution. Additionally a real problem is that in the my main equation I am discounting 20 payments and and I was not able to modify it as a linear equation yet due to missing knowledge about what to to with the exponents.
I hope anyone could help me.
Looking forward to hear from anyone.
I do not quite understand why you cannot solve your equation.
Take your function q:
q <- function(ytc) {
(5 / ((1 + (ytc / 4))^4 * ((1645 * 5 / 1826) - (1640 * 5 / 1826)))) +
(5 / ((1 + (ytc / 4))^4 * ((1736 * 5 / 1826) - (1640 * 5 / 1826)))) +
(5 / ((1 + (ytc / 4))^4 * ((1826 * 5 / 1826) - (1640 * 5 / 1826)))) +
100 / (((1 + (ytc / 4))^4 * ((1826 * 5 / 1826) - (1640 * 5 / 1826)))) - 100
}
and assuming you want to find the value of ytc for which function q is zero then you can use uniroot as follows:
uniroot(q, c(0,10))
and if you want a more accurate solution use
uniroot(q, c(0,10),tol = .Machine$double.eps^0.5)
Seems to work nicely.
Your function is buggy, because operator^ (exponentiation) takes a precedence over operator* (multiplication). foo^4*bar means (in virtually any programming language where ^ means exponentiation) "calculate foo^4 and then multiply the result by bar". You need (I removed extra brackets):
q <- function(ytc) {
5 / (1 + ytc / 4) ^ (4 * (1645 * 5 / 1826 - 1640 * 5 / 1826)) +
5 / (1 + ytc / 4) ^ (4 * (1736 * 5 / 1826 - 1640 * 5 / 1826)) +
5 / (1 + ytc / 4) ^ (4 * (1826 * 5 / 1826 - 1640 * 5 / 1826)) +
100 / (1 + ytc / 4) ^ (4 * (1826 * 5 / 1826 - 1640 * 5 / 1826))
- 100
}
or much better:
x1 = 1645 * 5 / 1826 - 1640 * 5 / 1826
x2 = 1736 * 5 / 1826 - 1640 * 5 / 1826
x3 = 1826 * 5 / 1826 - 1640 * 5 / 1826
q <- function(ytc) {
a = 1 + ytc / 4
5 / a ** (4 * x1) + 5 / a ** (4 * x2) + 5 / a ** (4 * x3)
+ 100 / a ** (4 * x3) - 100
}
Remember, as a newbie, if you will write complicated multi-line expression with huge number of nested brackets, you will almost always make a mistake. Avoid them like a plague! Divide them to comprehensible expressions.
I'm new to using R or any type of programming and I'm trying to differentiate 3xcos(xy) with respect to x. I've tried four different ways and was wondering which one is best/correct.
D(expression(3*x*cos(xy)),"x")
D(expression(3*x*cos*(xy)),"x")
D(expression(3*x*cos*(xy)),"x")
D(expression(3*x*cos*(x*y)),"x")
thanks in advance
Shane
None of those.
This is the correct expression:
D(expression(3*x*cos(x*y)),"x")
#3 * cos(x * y) - 3 * x * (sin(x * y) * y)
This treats xy as one variable:
D(expression(3*x*cos(xy)),"x")
#3 * cos(xy)
This treats xy as one variable and cos as a variable (and not a function):
D(expression(3*x*cos*(xy)),"x")
#3 * cos * (xy)
This treats cos as a variable:
D(expression(3*x*cos*(x*y)),"x")
#3 * cos * (x * y) + 3 * x * cos * y
Question is about the modulo operator on very large numbers.
For example consider a question where the total number of permutations are to be calculated.
Consider a number of 90 digits with each of the 9 numbers (1 to 9) repeating 10 times
so 90!/(10!)^9) is to be calculated
After reading many answers on StackOverflow I used logarithms to do it.
Now consider the log value to be 1923.32877864.
Now my question is how can I display the answer (i.e. 10 ^ log10(value) ) modulo of "m"?
And is this the best method for calculating the possible number of permutations?
Edit
Got the solution :)
Thanks to duedl0r.
Did it the way you specified using Modular Multiplicative Inverse.Thanks :)
I'm not sure whether this is actually possible and correct, but let me summarize my comments and extend the answer from Miky Dinescu.
As Miky already wrote:
a × b ≣m am × bm
You can use this in your equality:
90! / 10!^9 ≣m x
Calculate each term:
90!m / 10!^9m ≣m x
Then find out your multiplicative inverse from 10!^9m. Then multiplicate the inverse with 90!m.
update
This seems to be correct (at least for this case :)). I checked with wolfram:
(90!/10!^9) mod (10^9+7) = 998551163
This leads to the same result:
90! mod (10^9+7) = 749079870
10!^9 mod (10^9+7) = 220052161
do the inverse:
(220052161 * x) mod(10^9+7) = 1 = 23963055
then:
(749079870*23963055) mod (10^9+7) = 998551163
No proof, but some evidence that it might work :)
I would argue that the way to compute the total number of permutations modulo m, where m is an arbitrary integer (usually chosen to be a large prime number) is to use the following property:
(a * b) % m = ((a % m) * (b % m)) % m
Considering that the total number of permutations of N is N! = 1 * 2 * 3 * .. * N, if you need to compute N! % m, you can essentially apply the property above for multiplication modulo m, and you have:
((((1 * (2 % m)) % m) * (3 % m)) % m) * ..
EDIT
In order to compute the 90! / (10! ^ 9) value you could simplify the factors and then use multiplication modulo m to compute the final result modulo m.
Here's what I'm thinking:
90! = 10! * (11 * 12 * .. * 20) * (21 * 22 * .. * 30) * .. * (81 * 82 * .. * 90)
You can then rewrite the original expression as:
(10! * (11 * 12 * .. * 20) * (21 * 22 * .. * 30) * .. * (81 * 82 * .. * 90)) / (10! * 10! * ... * 10!)
At the numerator, you have a product of 9 factors - considering each expression in parenthesis a factor. The same is true for the denominator (you have 9 factors, each equal to 10!).
The first factor at the denominator is trivial to simplify. After that you still have 8 pairs that need simplification.
So, you can factor each term of the products and simplify the denominator away. For example:
11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 <=> 11 * 2 * 2 * 3 * 13 * 2 * 7 * 3 * 5 * 2 * 2 * 2 * 2 * 17 * 2 * 9 * 2 * 2 * 5
The denominator will always be: 2 * 3 * 2 * 2 * 5 * 2 * 3 * 7 * 2 * 2 * 2 * 2 * 3 * 3 * 2 * 5
After the simplification the second pair reduces to : 2 * 2 * 11 * 13 * 17 * 19
The same can be applied to each subsequent pair and you will end up with a simple product that can be computed modulo m using the formula above.
Of course, efficiently implementing the algorithm to perform the simplification will be tricky so ultimately there has to be a better way that eludes me now.