Why is the (second) if statement in the for loop not working?
2 views (last 30 days)
Show older comments
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 Comments
the cyclist
on 31 Aug 2020
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.
Accepted Answer
the cyclist
on 1 Sep 2020
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:
- calculates i_Last forward one step, so that the if statement will calculate against the "corrected" trajectory
- does not multiply the current value of i_Last by Faktor (because that's just the current position)
3 Comments
the cyclist
on 1 Sep 2020
Oh, right, I forgot that I had also adjusted the for loop. Glad it worked out.
More Answers (0)
See Also
Categories
Find more on Graphics Performance 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!