How to calculate mean-square deviation?

5 Ansichten (letzte 30 Tage)
Marcella Ward
Marcella Ward am 1 Dez. 2016
Beantwortet: Star Strider am 1 Dez. 2016
I have the following code, which animates a particle. I need to figure out how to calculate the mean-square deviation within my code. So, I need to calculate the difference between (X1-X0)^2, (X2-X1)^2 and so on for each iteration. In the end, I need to average everything: ∑((X2-X1)^2)÷199. How do I incorporate this into my existing code?
numMove = 200;
x_List = zeros(numMove,1);
y_List = zeros(numMove,1);
% make fig. & start loop
figure,
for t = 2:numMove
% add rand val between -1 and 1 to previous vals
% save as new x & y coordinates
x_List(t) = x_List(t-1) + 2*(rand()-0.3);
y_List(t) = y_List(t-1) + 2*(rand()-0.3);
%clear data currently on plot
% animate particle
cla
plot(x_List(1:t),y_List(1:t),'-r')
plot(x_List(t),y_List(t),'ob','linewidth',8)
axis([-20 20 -20 20])
% particle speed
pause(0.02)
end

Antworten (1)

Star Strider
Star Strider am 1 Dez. 2016
I’m not certain how ‘X0’, ‘X1’ and such relate to your code.
Here are a couple possibilities:
dxydt = diff([x_List, y_List]); % Take Differences Between Coonsecutive Values
mean_sqr_diff = mean(dxydt.^2); % Mean Of Squared Differences
mean_hypot = mean(hypot(x_List, y_List)); % Mean Of Distances

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by