Is taking average the right method to find individual answers?
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/552697/image.jpeg)
So over here I need to find out the dp values which are like d2, d3, d4, and so on will dN (N being the number of data points). So to solve this I open the brakets and take the terms to LHS and then divide that by the (u(k-i)^p) term which gives me dp value. But as there are multiple loops going on i get multiple values for each P th term. So what i did was to take the average after those loops get over to get only 1 term per each p loop.
%to get only one values
load('prbs165samples.mat') %dataset loaded
y = a(:,2); % output dataset (provided)
u = a(:,1); %input datast (provided)
na = 2;
nb = 2;
N = 161;
A = [0.2867 -0.2428];
B = [0.6607 -0.2732];
dp = [];
d = [];
tot = 0;
for p = 2:N+1
for i = 1:na
for j = 1:nb
for k = 3:N
LHS = y(k) + A(i)*y(k-i) - B(j)*u(k-j);
deno = (u(k-j).^p);
dp = [dp, LHS/deno];
tot = tot +(LHS/deno);
end
end
end
d = [d, tot/(na*nb*(N+1-3))];
tot = 0;
end
dp;
d
采纳的回答
Image Analyst
2021-3-16
编辑:Image Analyst
2021-3-16
No that's not right. You need two for loops. One to compute the "a" sum, then a separate loop (not nested) to compute the "b" sum. Then add the two sums together. yk = asumk + bsumk. Try something like this:
% Initialize variables to random numbers or zero
% or else use whatever values you have gotten in some other way.
N = 20;
u = rand(1, N);
d = rand(1, N);
na = 5
nb = 7
a = rand(1, na);
b = rand(1, nb);
k = 18;
y(k) = 0; % Initialize y
% Compute the first term, which is only one sum.
asum = 0;
for i = 1 : na
asum = asum + a(i) * y(k-1);
end
fprintf('The first sum = %f.\n', asum);
% Now compute the second term, which has two sums.
bsum = 0;
for i = 1 : nb
% First compute the third summation over p
udsum = 0;
for p = 2 : N
if (k-i) <= 0 || (k-i) > length(u)
% Cannot do this index value so exit the loop.
break;
end
udsum = udsum + d(p) * u(k-i) ^ p;
end
% Now add that third sum to u(k-i) and multiply by b(i):
%fprintf('(k-i) = %d.\n', (k-i));
if (k-i) >= 1 && (k-i) < length(u)
% If the indexes are ok, so the sum.
bsum = bsum + b(i) * (u(k-i) + udsum);
end
end
fprintf('The second sum = %f.\n', bsum);
% Now compute y(k) as the sum of the two summations:
y(k) = -asum + bsum
fprintf('Done running %s.m\n', mfilename);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!