Finding Mean of Vector x: A & B Equal?

  • Thread starter Thread starter magma_saber
  • Start date Start date
  • Tags Tags
    Mean Vector
AI Thread Summary
The discussion focuses on calculating the mean of a vector x using two for loops, A and B, which should yield the same result. The code provided attempts to use the mean of x as an index, leading to an "index out of bounds" error because the mean is not a valid index. The correct approach requires iterating over the actual indices of the vector x, not using the mean value as an index. The user is prompted to calculate the mean manually to understand the process better. Proper indexing and understanding of MATLAB's mean function are essential for resolving the issue.
magma_saber
Messages
73
Reaction score
0

Homework Statement


Below are two for loops that each find the mean of all the values in the vector x. A and B should be equal to the mean of the vector x.

Homework Equations


The Attempt at a Solution


A = 0;
for index = mean(x)
A = A + x(index)/length(x);
end

B = 0;
for index = mean(x)
B = B + index/length(x);
end

A file was provided that checks to see if its right. when i execute it, it says, "Attempted to access x(6); index out of bounds because numel(x)=5." what am i doing wrong? most of the code was already provided. all it asks is what "for index =" is equal to.
 
Physics news on Phys.org
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...

Similar threads

Replies
15
Views
2K
Replies
10
Views
2K
Replies
10
Views
2K
Replies
1
Views
1K
Replies
21
Views
3K
Replies
2
Views
1K
Back
Top