I want to check time series of the ordinary differential equation of 10 dimension .summed over all patches

1 次查看(过去 30 天)
clc;
clear all;
n = 20;
x=accumarray([2 3 n-1 n]',1);
B = toeplitz(x,x);
numEdgesToRewire = 2;
matrixSize=20;
edgesToRewire = randperm(matrixSize, numEdgesToRewire);
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;
y=[x(1);x(2);x(3);x(4);x(5);x(6);x(7);x(8);x(9);x(10);x(11);x(12);x(13);x(14);x(15);x(16);x(18);x(19);x(20)]
x0 = rand(1,20);
i = 1;
f = [];
function xprime = kau(t, x, B)
nn = length(x);
while i <= nn
f = [f; x(i)*(1 - theta*x(i)) - x(i+1) - (x(i)*x(i+1)) / (1 + x(i+1)); ...
(phi*x(i)*x(i+1)) / (1 + x(i+1)) - ita*x(i+1)];
i = i + 1;
end
xprime = f+B*y;
end
[t,x]=ode45(@(kau(t, x, B),tspan, x0);
H=x(1)+x(3)+x(5)+x(7)+x(9)+x(11)+x(13)+x(15)+x(17)+x(19);
P=x(2)+x(4)+x(6)+x(8)+x(10)+x(12)+x(14)+x(16)+x(18)+x(20);
plot(t, H, 'b');
hold on
plot(t, P, 'r');
  3 个评论
Rik
Rik 2023-8-15
Your code does not have any comments. It is therefor completely useles to anyone but you. And once you forget why you did exactly what you did, you will no longer be able to use it either. You should comment your code, explain what it is doing and why. That will help others find out what needs to change, and will help you remember what you did.
William Rose
William Rose 2023-9-11
That was a very thoughtful and constructive analysis from @Rik.
To which I would also add, please post the simplest version of your code that illustrates the problem you want to solve. I realize it is more work for you to make a slimmed-down version, but it is a courtesy to those who might help you, and is more likely to get you the answers you need.
Please explain what you mean by "I want to check time series of the ordinary differential equation of 10 dimension .summed over all patches".

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by