Storing Maximum values from each row
古いコメントを表示
Hi I am trying to find the minimum peak force and so I am trying to find the maximum value in each row, store that and then later choose the minimum from the matrix of maximums. I would then also need the corresponding variable values which give this minimum force. As you can see in my code, I am trying to do this using (i,:) to look at a specific row and all the possible 'j' (column) values. However, I think that it is only storing the maximum value from the last iteration/row rather than from every iteration/row. For the problem we were instructed to store the maximum value if it is larger than the last, hence the if F(i,:)>F_max bit. Any help much appreciated! Thank you in advance. This is my code...
m=4000; %kg
g=9.81;
L=4; %m
r_min=1.2; %m
r_max=2.2; %m
r=linspace(1.2,2.2,37); %m
theta_min=-20; %degrees
theta_max=80; %degrees
theta=linspace(-20,80,37); %degrees
phi=linspace(0,180,37); %degrees
gamma=phi+20; %degrees
%-----------------------------------
F_max=0;
for i=1:37
c_2(i)=((r_max^2)-(r_min^2))./(cosd(gamma(i)+theta_min)-cosd(gamma(i)+theta_max));
c_1(i)=(r_max^2)+c_2(i).*cosd(gamma(i)+theta_max);
a(i)=real(0.5*(((c_1(i)+c_2(i)).^(1/2))+((c_1(i)-c_2(i)).^(1/2))));
b(i)=real(c_2(i)/(2*a(i)));
for j=1:37
r(i,j)=sqrt((a(i)^2)+(b(i)^2)-(2*a(i)*b(i)*cosd(gamma(i)+theta(j))));
F(i,j)=(r(i,j)*m*g*L*cosd(theta(j)))/(b(i)*a(i)*sind(gamma(i)+theta(j)));
end
k=1;
if F(i,:)>F_max & F(i,:)~=Inf & F(i,:)~=-Inf
F_new(k)=F(i,:);
k=1+k;
end
F_max=max(k);
F_min=min(k);
theta_opt=theta(:);
a_opt=a(:);
b_opt=b(:);
r_opt=r(:);
phi_opt=gamma(:)-20;
end
Currently when run this code is giving the error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in MatLab_Code_main_3 (line 56)
F_new(k)=F(i,:);
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
