I wrote a code to get the value of M less than 0.6, but How can I modify the code so that I can get the value of M which lie between 0.5 to 0.6 ?,
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SAHIL SAHOO
am 14 Dez. 2022
Beantwortet: Image Analyst
am 14 Dez. 2022
ti = 0;
tf = 70E-8;
tspan=[ti tf];
KC = 1E-3;
for j = 1:100
y0= [(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
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*Y(:,6)) + exp(i.*Y(:,9)) + exp(i.*Y(:,12)) + exp(i.*Y(:,15)) ...
+exp(i.*Y(:,18)) +exp(i.*Y(:,21)) +exp(i.*Y(:,24)) + exp(i.*Y(:,27)) + exp(i.*Y(:,30)) + exp(i.*Y(:,33)) ...
+ exp(i.*Y(:,36)) + exp(i.*Y(:,39)) +exp(i.*Y(:,42)) + exp(i.*Y(:,45)) + exp(i.*Y(:,48)) + exp(i.*Y(:,51)) + exp(i.*Y(:,54))+ exp(i.*Y(:,57)) + exp(i.*Y(:,60))));
M(j) = max(abs(r));
end
% I want those value between 0.5 to 0.6, how can I do that?
n = M(M<0.6)
function dy = rate_eq(t,y,yita_mn,N,o)
dy = zeros(4*N,1);
dGdt = zeros(N,1);
dAdt = zeros(N,1);
dOdt = zeros(N,1);
P = 1;
a = 1;
T = 2000;
tp = 1E-12;
Gt = y(1:3:3*N-2);
At = y(2:3:3*N-1);
Ot = y(3:3:3*N-0);
k = 1E-3;
for i = 1:N
dGdt(i) = (P - Gt(i) - (1 + 2.*Gt(i)).*((At(i)))^2)./T ;
dAdt(i) = Gt(i)*(At(i));
dOdt(i) = -a.*Gt(i) + o(1,i).*tp;
for j = 1:N
dAdt(i) = dAdt(i) + yita_mn(i,j)*(At(j))*cos(Ot(j)-Ot(i));
dOdt(i) = dOdt(i) + yita_mn(i,j)*((At(j)/At(i)))*sin(Ot(j)-Ot(i));
end
end
dy(1:3:3*N-2) = dGdt;
dy(2:3:3*N-1) = dAdt;
dy(3:3:3*N-0) = dOdt;
n1 = (1:20)';
n2 = circshift(n1,-1);
n61 = n1 +60;
n62 = circshift(n61,-1);
n80 = circshift(n61,1);
j2 = 3*(1:20)-1;
j5 = circshift(j2,-1);
j8 = circshift(j2,-2);
j59 = circshift(j2,1);
dy(n61) = (o(1,n2).' - o(1,n1).').*tp - a.*(Gt(n2) - Gt(n1)) - (k).*(y(j2)./y(j5)).*sin(y(n61)) - (k).*(y( j5)./y(j2)).*sin(y(n61)) + (k).*(y(j8)./y(j5)).*sin(y(n62)) - (k).*(y(j59)./y(j2)).*sin(y(n80));
end
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 14 Dez. 2022
Try this
M = rand(6)
mask = M > 0.5 & M < 0.6
valuesInRange = M(mask)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Biological and Health Sciences finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!