How do I perform this operation using for loop? or any other approach?
    1 回表示 (過去 30 日間)
  
       古いコメントを表示
    
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 件のコメント
採用された回答
  Guillaume
      
      
 2016 年 2 月 8 日
        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
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
