How do I perform this operation using for loop? or any other approach?
8 views (last 30 days)
Show older comments
Hello, I'm trying to do approximate integration of this function using different time steps. I need to get the results of FF1 for each of the values of c in one operation. Thanks in advance
clc
clear
w = 20; %exciting/forcing frequency
p = 15;
T1 = 2*pi/w; %exciting/forcing period
n = 3*T1;
q0 = 10;
G = 0.05;
% c = 10:10:100; % need to get values of FF1 for this range of values;
c = 20; %this is one value of c;
ts = T1/c; %time step
t = 0:ts:n;
qt1 = q0*sin(w*t);
F1 = ts*qt1.*sin(p*t).*exp(G/2*p*t);
FF1 = cumsum(F1)
0 Comments
Accepted Answer
Guillaume
on 8 Feb 2016
I'm not sure where the difficulty lies for you. As you say in your question, simply use a for loop. You probably want to store each FF1 for each value of c. Since the number of elements in FF1 varies with c, you have to store them in a cell array. So:
%constant declarations
%...
timesteps = 10:10:100
FF1 = cell(1, timesteps); %preallocate array for speed
for tidx = 1:numel(timesteps)
c = timesteps(tidx);
ts = T1/c; %time step
t = 0:ts:n;
qt1 = q0*sin(w*t);
F1 = ts*qt1.*sin(p*t).*exp(G/2*p*t);
FF1{tidx} = cumsum(F1)
end
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!