I want to plot the summed (x(1)+x(3)​+x(5)+...x​(19)) vs time

4 views (last 30 days)
mks
mks on 14 Aug 2023
Edited: dpb on 14 Aug 2023
This question was flagged by Star Strider
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]);
% Avoid rewiring to the same node or existing edges
while node2 == node1 || B(node1, node2) == 1
node2 = randi([1, matrixSize]);
end
% Rewire the edge
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)];
i = 1;
f = [];
function xprime = kau(t, x, B)
nn = length(x); % Add this line to define nn
while i <= nn % Change this condition to include equal sign
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(i); ...
(phi*x(2*i-1)*x(2*i)) / (1 + x(2*i)) - ita*x(2*i) + dp*B*y2(i)];
i = i + 1; % Change this to increment i by 1
end
xprime = f; % Assign f to xprime
end
x0 = rand(1,20);
tspan=[0,1000];
[t, x] = ode45(@(t, x) kau(t, x, B), tspan, x0);

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!