Creating a Function based on Time

8 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2016-12-7
编辑:Walter Roberson 2016-12-7
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by