How to take the average of different initial conditions

1 回表示 (過去 30 日間)
Samson
Samson 2019 年 8 月 28 日
コメント済み: M 2019 年 9 月 10 日
I have a code and I need to run the code for different initial conditions, then save and finally take the average. See code below
a = 0.2; b = 0.2; c = 5.7; sigma = 16; beta = 4; rho = 45.92;
% initial condition
x = rand (9.1);
g = (0: 5: 60);
% g = 0.5;
% computing the trajectory
dt = 0.01;
tspan = 100,000;
xinput = x;
X = zeros (9, tspan);
deltaDR = zeros (length (g));
deltaRA = zeros (length (g));
for j = 1: length (g)
X (:, 1) = x;
for i = 1: tspan
xoutput = rk4angelstepb (@ attractor, dt, xinput, a, b, c, sigma, beta, rho, g (j));
X (:, i) = xoutput;
xinput = xoutput;
end

回答 (1 件)

M
M 2019 年 8 月 28 日
It is not clear what you want to do from the code you posted, especially the first loop :
for j = 1: length (g)
...
end
Could you give a bit more details and tell us where is the difficulty exactly ?
  2 件のコメント
Samson
Samson 2019 年 8 月 28 日
The first loop is my coupling values which I want to use for the different initial conditions. I need to run my code for atleast 100 set of initial condition which I have as
x = rand (9.1)
I was thinking if I need 100 initial values, I will have it as
rand([9,1,10])
But how do I construct the loop and then average all. Also, I believe I will have to redefine
deltaDR = zeros (length (g));
deltaRA = zeros (length (g));
This is my issue
M
M 2019 年 9 月 10 日
If you want to run the code for at least 100 iterations, you should not loop over length(g), because dimension of g is 1 x 13 .
Then, rand([9,1,10]) outputs a vector of dimensions 9 x 1 x 10, so you won't have your 100 sets of initial conditions.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by