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
i am wondering if it is possible to simplify:
T*V + V*T // V = V^(t) symmetric
where both operands are matrixes
I don't think this is possible due to the following considerations:
If we multiply two matrices A and T, where A is symmetric (i.e. A(i,j) = A(j,i)), we have the following:
For A*T we have that the item in row z and column s is computed as:
__n__
\
/ A(z,i)*T(i,s)
-----
i=1
For the other way around, T*A, we get for row z, column s:
__n__ __n__
\ \
/ T(z,i)*A(i,s) = / T(z,i)*A(s,i)
----- -----
i=1 i=1
So, as long as we do not know anything about the entries T(i,j) in T, I think we can not say how these sums relate to each other.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to have this loop but it says its not possible. How can I create these kinds of loops?
for i in range (sposA,sposB) and for j in range(eposB+1,sposB,-1):
if tempstr[i] == ctempstr[j]:
pcount += 1
In basically any language, such a construct would be ambiguous. Are you trying to loop in two dimensions (if each index list is x and y long, are you doing x*y things total?) or in parallel (are the indices the same length, e.g. x, and paired, so you only do x things?).
If you want to loop in two dimensions, you simply nest loops:
for i in range(x):
for j in range(y):
doStuff(i, j)
If they're parallel, you can either create some functional dependence between them so you can convert index i into index j, or combine the indicies:
for i in range(x):
j = f(i)
doStuff(i, j)
or
for i, j in zip(range(x), range(y)):
doStuff(i, j)
The above stuff is in Python-pseudocode, but the control structures are broadly applicable in any imperative language (C, Python, Java...).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
How can I generate a matrix in Matlab that has 5 rows and some specific number of columns and the elements may only be binary numbers and the column sum has to be less or equal to 3?
Some possibilites without loops:
Using strings:
D = 5;
S = 3;
numbers = str2mat(dec2bin(0:2^D-1))-'0';
numbers = numbers(sum(numbers,2)<=S,:);
Using combinatorial numbers, one line:
numbers = [zeros(1,D); cell2mat(arrayfun(#(s) fliplr(full(sparse((1:nchoosek(D,s)).'*ones(1,s), nchoosek(1:D,s), 1))), 0:S, 'uni', 0).')];
How about this: The maximum binary number, that you can represent by 5bit is 2^5-1 = 31 and skip through these to find the ones with sum of digits <= 3.
Something like
n = 1:1:31;
for ii = 1:length(ii)
bin = dec2bin(ii)
digitSum = 0
for d = 1:length(bin)
digitSum = digitSum + str2num(bin(d))
end
if (digitSum <= 3)
%store results
end
end
Here is a vecotorized solution to provide all occurences efficiently:
Bstr =dec2bin(1:31);
Bstr(sum(dec2bin(0:31),2)<=sum('00111'),:)=='1'
Inspired by the solution of #pyStarter
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 was using this formula to calculate last m digits of 2^n.
pow=2+(n-m)%(4*5^(m-1))
ans =(2^pow)%(10^m)**
But this is not working for n=2009 and m=3.
Suggest any error in my calculation or a better formula if there is.
I don't understand what your formula is doing, but the simplest way is to calculate (2^2009)%(10^m) . Here is a pseudo code to find (x^y)%mod in O(log y). Put x=2, y=2009 and mod=10^m
power(x,y)
{
if( y == 0)
return 1
temp = power(x, y/2)
if (y%2 == 0)
return (temp*temp)%mod
else
return ((x*temp%mod)*temp)%mod
}
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
There are n independent random variables X1,X2..Xn. Each random variable can take value of either 0 or 1. The probability that a variable Xi has a value of 1 is 1/n. What is the expected value of square of sum of X1..Xn.
This may be homework, so I'll give a few hints:
We want E((\sum_i X_i) ^2). Now show that:
E((\sum_i X_i)^2) = E(\sum_i X_i^2 + 2\sum_{1<= i < j <= n} X_i * X_j)
= n * E(X_i^2) + 2 * choose(n, 2) * E(X_i * X_j)
Now all you need is:
E(X_i^2), E(X_i * X_j)
For any i and j, since they are i.i.d.
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 12 years ago.
Improve this question
Is there some way to calculate the inverse factorials of real numbers?
For example - 1.5 ! = 1.32934039
Is there some way to obtain 1.5 back if I have the value 1.32934039?
I am trying
http://www.wolframalpha.com/input/?i=Gamma^(-1)[1.32934039]
but that is a fail.
Using wolframalpha.com, you can ask for
Solve[Gamma[x+1]==1.32934039,x]
As mentioned in the comments, Gamma does not have a unique inverse. True even when you are solving for a conventional factorial, e.g.
Solve[Gamma[x+1]==6,x]
yields several answers, of which one is 3.
Instead of using Gamma[] in WolframAlpha, you can also use Factorial[]:
Solve[Factorial[x]==6,x]
Solve[Factorial[x]==1.32934039,x]
David Cantrell gives a good approximation of Γ-1(n) on this page:
k = the positive zero of the digamma function, approximately 1.461632
c = Sqrt(2*pi)/e - Γ(k), approximately 0.036534
L(x) = ln((x+c)/Sqrt(2*pi))
W(x) = Lambert W function
ApproxInvGamma(x) = L(x) / W(L(x) / e) + 1/2
For integers you can do:
i = 2
n = someNum
while (n != 1):
n /= i
i += 1
return (i==1 ? i : None)
The factorial for real numbers has no inverse. You say that "each function must have an inverse". That is incorrect. Consider the constant function f(x)=0. What is f^-1(42)? For a function to be inverse it must be both an injection and a surjection.