Effacer les filtres
Effacer les filtres

Creating a Function based on Time

35 vues (au cours des 30 derniers jours)
Viper224
Viper224 le 7 Déc 2016
As the title suggests I'm trying to create a function of time that computes lift and drag coefficients for the first 5 seconds and then what they are after 5 seconds. I don't have too much MatLab experience so I'm probably not doing this right. Can someone please help?
function[CL, CD, CP] = LiftandDrag(t, CLi, CDi)
t = 1:100;
CDi = 0.01; %Initial canopy Drag Coefficient
CLi = 0.0; %Initial canopy Lift Coefficient
if t < 5
CL = .2*t+CLi;
CD = 0.038*t+CDi; %drag coeffcient of chute
CP = 2; %drag of payload
elseif t > 5
CL = 1; %Inflated canopy Lift Coefficient
CD = .2; %Inflated canopy Drag Coefficient
CP = 2; %Payload Drag Coefficient
end

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Déc 2016
Modifié(e) : Walter Roberson le 7 Déc 2016
Vectorize. Logical indexing.
function [CL, CD, CP] = calcLiftAndDrag
t = 1:100;
CDi = 0.01; %Initial canopy Drag Coefficient
CLi = 0.0; %Initial canopy Lift Coefficient
[CL, CD, CP] = LiftandDrag(t, CLi, CDi);
function[CL, CD, CP] = LiftandDrag(t, CLi, CDi)
CL = zeros(size(t));
CD = zeros(size(t));
CP = zeros(size(t));
mask = t <= 5;
CL(mask) = .2*t(mask)+CLi;
CD(mask) = 0.038*t(mask)+CDi; %drag coeffcient of chute
CP(mask) = 2; %drag of payload
CL(~mask) = 1; %Inflated canopy Lift Coefficient
CD(~mask) = .2; %Inflated canopy Drag Coefficient
CP(~mask) = 2; %Payload Drag Coefficient

Plus de réponses (0)

Catégories

En savoir plus sur Elementary Math dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by