Re: [Scilab-users] Avoiding a loop

2017-05-12 Thread Frieder Nikolaisen
Hello Tim, Yes. batt is the is the State of Charge of the battery. P(n,2) (kN) is the power taken rom battery, engine or both. I will calculate the battery in As, so P(n,2) is only an in alternate value - but thats fare to complicated for the example code. "Proving that it's correct will be

Re: [Scilab-users] Avoiding a loop

2017-05-11 Thread Tim Wescott
Depending on how often you switch between battery and generator, and how icky-picky you're willing to be, there may be a way to reduce computation. It looks like the term P(n,2) * (P(n+1,1) - P(n,1)) is always there, and you're either adding it to 'gen' (is it energy production?) or subtracting

Re: [Scilab-users] Avoiding a loop

2017-05-11 Thread Frieder Nikolaisen
Thanks for all the answers. I feared that there is no way around a loop. During the process batt (Battery) is charged and discharged. In my example, it is only discharged. I will code the entire problem with a loop, maybe somebody knows something to speed up the process with the full

Re: [Scilab-users] Avoiding a loop

2017-05-10 Thread Samuel Gougeon
Le 10/05/2017 à 17:25, Frieder Nikolaisen a écrit : There was a piece of code missing: P = [ 1, 0; 2, 50; 5, 110; 10, 80; 11, 200 15, 0]; batt = 1000; gen = 0; n = 1 for n=1:5 if P(n,2) > 100 then if batt > 800 then batt

Re: [Scilab-users] Avoiding a loop

2017-05-10 Thread Amanda Osvaldo
What it's the equation you need to compute ?Perhaps I can help. I think it's possible to compute with something in this way: map = find (P(:,2) > 100 ); if batt > 800 then batt = batt - P(map,2) * (P(map+1,1) - P(map,1)); end On Wed, 2017-05-10 at 17:23 +0200, Frieder Nikolaisen wrote: >