hi, I'm student in a space compagny and I have built a matlab soft to compute orbit , but the run take more than 48h, in fact, one function was call more than billion time, and also I search to win some milliseconde in my funtion.
this funtion compute angle between 2 vectors input : 2 vectors v & u (3 by n) output : angle between u and v in rad (n by 1)
here after the code , but I don't find more solution to optimize it :
function angle = searchAngle(u, v)norm = @(v) sqrt(sum(v.^2, 2));dot = @(u, v) sum(u .* v, 2);cross = @(a, b) [ a(:,2) .* b(:,3) - a(:,3) .* b(:,2), ... a(:,3) .* b(:,1) - a(:,1) .* b(:,3), ... a(:,1) .* b(:,2) - a(:,2) .* b(:,1) ];normVect = norm(u) .* norm(v);dotVect = dot(u, v); threshold = normVect * 0.9999;idx1 = dotVect > threshold;axis = cross(v(idx1,:), u(idx1,:));angle(idx1) = asin(norm(axis) ./ normVect(idx1));idx2 = dotVect < -threshold;axis = cross(v(idx2,:), u(idx2,:));angle(idx2) = pi - asin(norm(axis) ./ normVect(idx2));idx = ~(idx1 | idx2);angle(idx) = acos(dotVect(idx) ./ normVect(idx));end
thx for any help
Best Answer