Answered
While loops, please help
Here's something to get you started: x = linspace(0,20,500); will create a vector of 500 values of x uniformly spaced b...

11 years ago | 1

Answered
Monte Carlo Pi while loop iterations
Roughly speaking, the expected variance from the mean in an independent random series is proportional to the reciprocal of the s...

11 years ago | 2

Answered
Most efficient way to do matrix operation v'*M*v
Assuming the values in V are real, val = 1-sum((V/R).*V,2); If V has complex-valued elements, change that to val ...

11 years ago | 2

| accepted

Answered
How to generate Zero mean and unit variance
If you want a uniform distribution do this: n = 1024; x = sqrt(3)*(2*rand(n,1)-1); The random variable x will have ...

11 years ago | 2

| accepted

Answered
Multiplying rows of matrix without bsxfun or for loops
a = size(A,1); b = size(B,1); C = A(repmat(1:a,b,1),:).*repmat(B,a,1);

11 years ago | 2

| accepted

Answered
how to get 3 indices of the min value?
[~,ix] = min(err(:)); [i1,i2,i3] = ind2sub(size(err),ix); The minimum value is err(i1,i2,i3).

11 years ago | 1

| accepted

Answered
Splitting up a vector into a matrix
new = reshape(v,sqrt(length(v)),[]).'; % <-- The transpose is needed

11 years ago | 0

Answered
Thanks! Determine εmatch by finding smallest ε = 2^(-k)?
Writing code to determine that should be rather easy. Use a while-loop to repeatedly test whether (1+2^(-k))-1 is non-zero as t...

11 years ago | 2

Answered
Using for loops with a recurrence relation to find intervals where the plot acts differently.
You have an error in your recurrence formula, the line y(n+1) = y(n)+h(k)*((-y(n))^2+(4.5*y(n))-3.5); should be y...

11 years ago | 2

Answered
Random Variable with exponential distribution of Probablity Density Function
If we call the pdf of y, 'pdfy', then pdfy(t) = 1/(2*a*sqrt(t))*exp(-1/a*sqrt(t)) Note the interesting fact that as t a...

11 years ago | 2

Answered
??? Index exceeds matrix dimensions.
I suspect the trouble lies with 'data333'. It may not have as many as 12 columns. If not, the lines "c=(1/(d^2))*data333(j,col...

11 years ago | 2

Answered
can any one tell me how this code is working??
This does not seem like good code to me. It is likely that what it does is not what its author intended. For example, if one...

11 years ago | 2

Answered
Help solve 2 equations with 4 unknowns
I don't think the approach you describe or anything like it would succeed, David. The 'solve' function is not smart enough for ...

11 years ago | 2

Answered
How do I compare two large matrices?
Just modify Rick's code a bit: m = 10; [~,p] = sort(abs(bsxfun(@minus,x,y)),2); new = zeros(size(x,1),m); for ...

11 years ago | 2

Answered
store values in array in nested for loop
To get the correct minimum values, replace "clearvars RS" with "ss=1;". If you want to retain a record of these two minimums ...

11 years ago | 1

| accepted

Answered
How to write code for hankle and toeplitz matrix?
My apologies! I was not thinking clearly when I wrote the nonsensical A.^(0:9). The following should produce the desired two a...

11 years ago | 3

| accepted

Answered
Random number generation problem
You say *"the number of users are greater than the number of channels, so there will be a repetition of channel assignment"* . ...

11 years ago | 1

Answered
Question about vector angular separation
This sounds like homework, so I will only give hints. The cosine of the angle between two vectors is equal to their dot product...

11 years ago | 2

Answered
How to write code for hankle and toeplitz matrix?
phi = toeplitz(C*A.^(0:9)*B,zeros(1,4)); It is assumed that C*A^n*B is a scalar.

11 years ago | 0

Answered
help on randfixedsum error?
The arguments you use for 'randfixedsum' are rather strange! It is the columns whose sum must be 5 and your columns have only on...

11 years ago | 1

| accepted

Answered
I need to use for loops to find thematrix product P and Q.
What you are computing there is the Kronecker tensor product: M = kron(P,Q); and not "% M(i,j) = P(i,:)*Q(:,j)". See: ...

11 years ago | 0

Answered
how to solve the following Probability density function in matlab?
There is an obvious misprint in the stated interval. It should be: 1/4 0<=x<3 f(x) = 5/...

11 years ago | 2

| accepted

Answered
Calculating Euclidean distance of pairs of 3D points.
Use matlab's 'pdist' and 'squareform' functions

11 years ago | 0

Answered
solving a non-linear problem
I was overly pessimistic about finding solutions to your most recent set of equations. I had been testing the wrong collection ...

11 years ago | 2

Answered
How to plot a function is equal to a constant?
The range for x = -5:5 includes the value x = 0 for which log(0) is minus infinity. I would suggest x = linspace(1,2,1000...

11 years ago | 1

| accepted

Answered
why does this trig iteration generates complex numbers?
You are apparently trying to solve the trigonometric equation sin(theta) = (sqrt(d3*d3 - ((h-Ah)-d4*cos(theta))^2) + v + A...

11 years ago | 3

Answered
optimal solution of a matrix
It isn't entirely clear what you are asking. If it is allowed to select only a portion of the non-zero values in a column, then...

11 years ago | 2

Answered
Most populated range of floating point numbers in array
Perhaps you won't consider this for-loop solution elegant, but it should be computationally efficient. I will assume that your ...

11 years ago | 3

| accepted

Answered
Implementing a numerical integration expression
Use matlab's 'integral2' function. It provides for inner integration limits to be functions of the outer variable of integratio...

11 years ago | 2

Answered
Associated Legendre polynomials are not orthogonal
As cyclist has noted, the factor 1/(1-x^2) is essential in performing an orthogonality test. The Associated Legendre "polynomia...

11 years ago | 3

Load more