Creating a Function based on Time
13 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Walter Roberson
on 7 Dec 2016
Edited: Walter Roberson
on 7 Dec 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
0 Comments
More Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!