Friends,
I'm trying to refine my code.It works fine but I have four if conditions which I want to make more efficient. Is there an alternative way to do it?
i=1; while (VMPH<=60) % Vehicle speed
t(i+1) = t(i)+delt; Vmps(i+1) = Vmps(i)+((delt*(Facc(i)))/Vm); VMPH(i+1) = Vmps(i+1)/0.44704; % Vehicle forces
Fr(i+1) = Fr(1); Fd(i+1) = 0.5*Af*Cd*(Vmps(i+1))^2; % Speed conditions
ig(i+1) = 3.78; N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt); if N(i+1) > 2150 ig(i+1) = 2.06; N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt); end if N(i+1) > 2150 ig(i+1) = 1.58; N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt); end if N(i+1) > 2150 ig(i+1) = 1.21; N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt); end if N(i+1) > 2150 ig(i+1) = 0.82; N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt); end % Power and performance
Tao_b(i+1) = interp1(Speed,Torque,N(i+1)); Tao_w(i+1)= Tao_b(i+1)*io*ig(i+1)*etadrive; Ft(i+1) = Tao_w(i+1)/Dt*2; Pb(i+1) = 2*pi*Tao_b(i+1)*N(i+1)/60; % Acceleration force
Facc(i+1) = Ft(i+1)-Fd(i+1)-Fr(i+1); i=i+1; end
Thank You!
Best Answer