Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

please complete the time series code

4 vues (au cours des 30 derniers jours)
mks
mks le 14 Août 2023
Clôturé : John D'Errico le 14 Août 2023
clc;
clear all;
n = 10;
x=accumarray([2 3 n-1 n]',1);
B = toeplitz(x,x);
% G=graph(B);
% plot(G)
% Parameters
% matrixSize = 10; % Size of the matrix
numEdgesToRewire = 2; % Number of edges to rewire
% Create an initial matrix
% Y = B;
matrixSize=10;
% Randomly select two edges to rewire
edgesToRewire = randperm(matrixSize, numEdgesToRewire);
% Iterate through the edges to rewire
for i = 1:numEdgesToRewire
node1 = edgesToRewire(i);
node2 = randi([1, matrixSize]);
while node2 == node1 || B(node1, node2) == 1
node2 = randi([1, matrixSize]);
end
B(node1, node2) = 1;
B(node2, node1) = 1;
end
disp(B)
theta = 0.3;
dh = 2^-9;
dp = 2^-7;
phi = 3;
ita = 1;
y1 = [x(1); x(3); x(5); x(7); x(9); x(11); x(13); x(15); x(17); x(19)];
y2 = [x(2); x(4); x(6); x(8); x(10); x(12); x(14); x(16); x(18); x(20)];
x0 = rand(1,20);
tspan=[0,1000];
i = 1;
f = [];
function xprime = kau(t, x, B)
nn = length(x);
while i <= nn
f = [f; x(2*i-1)*(1 - theta*x(2*i-1)) - x(2*i) - (x(2*i-1)*x(2*i)) / (1 + x(2*i)) + dh*B*y1; ...
(phi*x(2*i-1)*x(2*i)) / (1 + x(2*i)) - ita*x(2*i) + dp*B*y2];
i = i + 1;
end
xprime = f;
end
[t, x] = ode45(@(t, x) kau(t, x, B), tspan, x0);
for i = 1:20
figure;
plot(t, x(:, i), 'LineWidth', 2);
end
  1 commentaire
John D'Errico
John D'Errico le 14 Août 2023
Déplacé(e) : John D'Errico le 14 Août 2023
It looks complete to me. What do we see? We see uncommented, virtually undocumented code, that does something we are not told about, solving some unspecified problem. The few comments in there are not pertinent to anything, since they tell us nothing about what the code should do, or even why those lines of code were written. As such, it is as perfectly complete as it can possibly be. Maybe your goal is to have a code that fails, in some inscrutable way? Looks perfect.
The point being, CAREFULLY explain what it should do. Explain what you did not do, and where is the failure. If you want help, that is.

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by