フィルターのクリア

Need help creating a "for loop" for the following series.

2 ビュー (過去 30 日間)
Wilmer
Wilmer 2014 年 9 月 26 日
コメント済み: Wilmer 2014 年 9 月 30 日
the above equation is used to determined certain polynomial coefficients. I tried creating a "for" loop for the function where y = 1,2,....,v and L0 = 1. where v is a scalar input like 3. I tried creating a "for loop" where instead starting from i = 0, it starts from 1, but the L vector (input) does not want sum up the correct values. I am suppose to get f2y = [0 -0.75 0 0.1875 0 -0.156] but cannot seem to work backwards. Please help!!!
Here is what I came up so far,
L = [1.5 0.75 0.125 0 0 0];
v = 3;
f2y = zeros(1,2*v);
for y = 2:v,
f2y(2) = 2*L(1)*L(3) + (-1)^(1) * L(2)^(2);
for ii = 1:v,
f2y(2*y) = (-1)^(ii-1)*2*L(ii)*L(2*y-ii) + (-1)^(y) * L(y+1)^(2);
end
end
  2 件のコメント
Star Strider
Star Strider 2014 年 9 月 26 日
‘where u is a scalar input like 3’
Unfortunately, u is nowhere to be found in the expression you posted. Could that be the problem?
Wilmer
Wilmer 2014 年 9 月 26 日
meant "v" not "u".....

サインインしてコメントする。

採用された回答

Nalini Vishnoi
Nalini Vishnoi 2014 年 9 月 29 日
In my understanding you are trying to convert the above equation to MATLAB code using 'for' loops.
The last term in the equation is outside the summation.
Since the L vector starts from 0, I would recommend appending the first index of vector L with a 1 and using L(t+1) wherever L(t) is required. Again, as MATLAB indices start from 1, we can use (i-1) wherever an 'i' is occurring in the equation. This would get rid of the requirement to compute f(2) separately.
The code may look like the following:
L = [1 1.5 0.75 0.125 0 0 0];
v = 3;
f2y = zeros(1,2*v);
for y = 1:v,
for i = 1:y
f2y(2*y) = f2y(2*y)+(-1)^(i-1)*2*L(i)*L(2*y-(i-1)+1) ; % L((i-1)+1) becomes L(i)
end
f2y(2*y) = f2y(2*y) + + (-1)^(y) * L(y+1)^2;
end
This seems to produce the expected results for the data provided.
  1 件のコメント
Wilmer
Wilmer 2014 年 9 月 30 日
thank you for the help. the loop works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by