Azzera filtri
Azzera filtri

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 ?,

3 visualizzazioni (ultimi 30 giorni)
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));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
((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*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

Risposta accettata

Image Analyst
Image Analyst il 14 Dic 2022
Try this
M = rand(6)
M = 6×6
0.4981 0.1748 0.5274 0.2588 0.0256 0.8047 0.5549 0.2718 0.5634 0.3848 0.9192 0.5669 0.3199 0.4258 0.0928 0.0369 0.5816 0.0009 0.9879 0.5313 0.3875 0.9770 0.6493 0.4357 0.2661 0.8631 0.5638 0.0952 0.7421 0.7805 0.3278 0.7367 0.3974 0.5681 0.0897 0.6884
mask = M > 0.5 & M < 0.6
mask = 6×6 logical array
0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0
valuesInRange = M(mask)
valuesInRange = 8×1
0.5549 0.5313 0.5274 0.5634 0.5638 0.5681 0.5816 0.5669

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by