Why is the (second) if statement in the for loop not working?

1 回表示 (過去 30 日間)
pm96
pm96 2020 年 8 月 31 日
編集済み: pm96 2020 年 9 月 1 日
Hi, after many tries i still not understand why the second if statement inside the for loop isn't working. The picture shows the result of a simulation which should match with the result of my matlab code.
  6 件のコメント
the cyclist
the cyclist 2020 年 8 月 31 日
I see two problems:
First: If you zoom in to the early part of your plot (and plot your data with '.-' to show the individual points), you'll see that your first "correction" (when i==5) to prevent going past the upper bound actually puts the new point below the lower bound.
Second: You always do your conditional tests against the "uncorrected" trajectory. After i==5, every point is above the upper bound, so that is the clause that is entered.
I haven't looked how to correct these flaws.
pm96
pm96 2020 年 8 月 31 日
Hi cyclist,
thx. I actually recognized that and i'm still trying to find a solution for that. So far without success. Hope to find a solution soon or maybe one of you know how to solve that.

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

採用された回答

the cyclist
the cyclist 2020 年 9 月 1 日
I don't know if this is perfectly correct, but it is certainly closer:
Where you have
i_Last(i) = Faktor*(i_0+(i_Amp*(1-exp(-(dt/tau_Last)))));
I instead put
i_Last(i) = (i_0+Faktor*(i_Amp*(1-exp(-(dt/tau_Last)))));
i_Last(i+1) = (i_Last(i)+Faktor*(i_Amp*(1-exp(-(dt/tau_Last)))));
This does two things:
  1. calculates i_Last forward one step, so that the if statement will calculate against the "corrected" trajectory
  2. does not multiply the current value of i_Last by Faktor (because that's just the current position)
  3 件のコメント
pm96
pm96 2020 年 9 月 1 日
編集済み: pm96 2020 年 9 月 1 日
ok, i solved that. it was the wrong condition for the length of the for-loop. it should be T1*SR not T1*SR+1. And SR should be > 10000 so the signal gets more clear. Thx all for your help.
the cyclist
the cyclist 2020 年 9 月 1 日
Oh, right, I forgot that I had also adjusted the for loop. Glad it worked out.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by