[Scilab-users] Avoiding a loop
Tim Wescott
tim at wescottdesign.com
Wed May 10 18:51:49 CEST 2017
I had a cool solution for you, but then I saw that you're implementing
a difference equation, with current values of batt (for instance)
depending on prior values.
I think that no, you can't eliminate the loop. If speed is a concern
and if you're using the code heavily, you can put it in a C function --
but that's only for really heavy pro users.
On Wed, 2017-05-10 at 17:23 +0200, Frieder Nikolaisen wrote:
> Hello,
> I did write an example code, but I do not like the time consuming way
> I solved the problem. With 50 000 lines in the matrix, it wouldn't be
> fun.
> How can I avoid using the for-loop?
> 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 = batt - P(n,2) * (P(n+1,1) - P(n,1))
> else
> gen = gen + P(n,2) * (P(n+1,1) - P(n,1))
> end
>
> else
> batt = batt - P(n,2) * (P(n+1,1) - P(n,1))
> end
> disp('n ' + string(n))
> disp('batt ' + string(batt))
> disp('gen ' + string(gen))
> end
> Thanks alot!
>
> Best regards
> Frieder
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
--
Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell: 503.349.8432
More information about the users
mailing list