A problem in writing a code

2 ビュー (過去 30 日間)
Hamed P. Azad
Hamed P. Azad 2011 年 12 月 9 日
I have a problem in a code.
y_d = zeros (N,1)
for cont = 1:N
y_d (cont,1) = u (cont);
end
u_minus = zeros (N,1);
Output = zeros (N,1);
for count = 1:N
Output (count,1) = y_sin_real (count);
end
for c = 0:N
mat2 = y_d - ((h_minus * u_minus) - (Output - y_d));
u_plus = mat1\(h_plus_t * Q)* mat2;
Output = (h_plus * u_plus) + (h_minus * u_minus);
u_minus = [u_minus ; u_plus(1)];
u_minus = u_minus (2 : N+1);
error = abs(y_d) - abs(Output);
end
as you can see, i first give an initial state to Output to use in calculation, but in the loop, i'm changing it's value N times. but it's not workin and in the end of the loop i still have the initial numbers for Output.
what is the problem???
thanks.
  1 件のコメント
Dr. Seis
Dr. Seis 2011 年 12 月 9 日
You should also show how the other variables (i.e., the one in your third "for" loop) are created above. Or at least tell us their dimensions.

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

回答 (3 件)

Hamed P. Azad
Hamed P. Azad 2011 年 12 月 9 日
yes, the problem is in the 3rd for loop, but the variables are set correctly, and the code runs fine; except for the "Output" that stays the way it was initiated.
the code is long and the variables are set in different loops.
  2 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 12 月 9 日
Can you provide us with enough of the input data that we can replicate this?
Dr. Seis
Dr. Seis 2011 年 12 月 9 日
Okay... then what are their dimensions? Are they also Nx1 vectors?

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


Daniel Shub
Daniel Shub 2011 年 12 月 9 日
One issue is that in the 3rd loop you overwrite Output. All you work in the second loop is lost on the first iteration of the 3rd loop. The line:
Output = (h_plus * u_plus) + (h_minus * u_minus);
is potentially problematic.

Dr. Seis
Dr. Seis 2011 年 12 月 9 日
The first line in your third "for" loop is:
mat2 = y_d - ((h_minus * u_minus) - (Output - y_d));
which is basically:
mat2 = h_minus * u_minus - Output;

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by