how to display those value of M, which is only less than 1?
1 view (last 30 days)
Show older comments
ti = 0;
tf = 70E-8;
tspan=[ti tf];
KC = 1E-4;
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));
((-3.14).*rand(20,1) + (3.14).*rand(20,1))];
yita_mn = [
0 1 0 0 0 0 0 0 0 0 0 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p(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
% here the 100 values of M will be generate, I want to know how many out of
% 100 have the M value less than 1.000?
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 = 2;
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-4;
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 Comments
Answers (1)
Zahrah Walid
on 3 Dec 2022
I'm not sure if you want to replace the values higher than 1 by one specific value or you want to remove them completely; if it is the latter you can add this statment after the for loop:
M=M(int8(M)<1)
Take care that due to Mtlab precision the "0.9999999" can be displayed to you as "1.000" but when you do any logical opertation it deal by its actual value (because this case exists in your code). If you want to print actual values less than 1, you should use this statment instead:
M=M(M<1)
If your purpose was the former, then you can add if condition inside your for loop as follows:
if (max(abs(r))<1)
M(j)=max(abs(r))
else
M(j)=1; %the value you want
end
Care to not use this if condition if you want to remove the values higher than 1 as it will results in NAN elements in your array.
See Also
Categories
Find more on Phased Array Design and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!