Is taking average the right method to find individual answers?
1 view (last 30 days)
Show older comments
Ankitha Pai
on 16 Mar 2021
Commented: Ankitha Pai
on 16 Mar 2021
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
3 Comments
Accepted Answer
Image Analyst
on 16 Mar 2021
Edited: Image Analyst
on 16 Mar 2021
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);
More Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!