How to calculate mean-square deviation?

조회 수: 5 (최근 30일)
Marcella Ward
Marcella Ward 2016년 12월 1일
답변: Star Strider 2016년 12월 1일
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

답변 (1개)

Star Strider
Star Strider 2016년 12월 1일
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

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by