help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any possible optimization?


From: Daniel Arteaga
Subject: Re: Any possible optimization?
Date: Mon, 10 Jan 2011 17:28:33 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; ca-ES; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7

Al 10/01/11 17:03, En/na c. ha escrit:

Your system can be easily solved explicitely so the function can be written as:

function [s,t] = intersectionPoint2(a,b,c,d)

   aa = (b - a);
   bb = (c - d);
   cc = (c - a);
   det = (-aa(2)* bb(1) + aa(1)* bb(2));
   s   = (bb(2)* cc(1) - bb(1) *cc(2))/det;
   t   = -(aa(2)* cc(1) - aa(1) *cc(2))/det;

endfunction

which is (very slightly) faster:

tic, for ii=1:1e5, [s,t] = intersectionPoint2(a,b,c,d); endfor; toc
Elapsed time is 13.16 seconds.
tic, for ii=1:1e5, [s,t] = intersectionPoint(a,b,c,d); endfor; toc
Elapsed time is 21.2 seconds.

Thank you! A 60% speed increase is noticeable. It will make a difference in my code




reply via email to

[Prev in Thread] Current Thread [Next in Thread]