function [v_best,res_eff_best] = eff_calc(interp_power,v_a, TC, v_w, WD ) %eff_calc calculates the best speed and best efficiency of the plane for a given %efficiency curve, track, wind speed and wind direction WA = (WD-TC)*pi/180; WA_grad = 180/pi*WA; if WA==0 WA=0.0000001; %durch Null teilen verhindern end if WA==pi || WA==-pi WA=pi*1.00001; %Singularität verhindern end v_a(v_w>v_a) = v_w; %complexe Zahlen verhindern durch |asin_argument| < 1 v_g = v_a.*(sin(WA+asin(v_w./v_a.*sin(WA)))) ./ sin(WA); eff=v_g./v_a; for idx=1:numel(v_a) if eff(idx)<0 || v_w>=v_a(idx) eff(idx) = 0; end end res_eff= v_a./interp_power.*eff.*100./max(v_a./interp_power); %Effizienz des Fliegers (Formel hat ggf. Optimierungspotenzial^^) [~,idx_best] = max(res_eff); v_best = v_a(idx_best); res_eff_best = res_eff(idx_best); %Ergebnis soll Strecke/Energie in % sein (Bezug auf Windstille) figure(1) plot(v_a, res_eff); hold on plot(v_a(idx_best), res_eff_best, 'marker','x'); xlabel('airspeed/ km/h') ylabel('efficiency / %') end