Need help using same equation for multiple data points.

1 回表示 (過去 30 日間)
JAKE WISNIEWSKI
JAKE WISNIEWSKI 2021 年 11 月 7 日
コメント済み: JAKE WISNIEWSKI 2021 年 11 月 9 日
clear
clc
close all
%%Given Information
L1=[100 6 7];
L2=[40 2 9];
L3=[120 7 3];
L4=[80 9 8];
theta_2=[40 30 85];%theta2 in degrees
OC=[1 1 2];%1 for open 2 for crossed
rp=[0 6 9];
d_a=[0 30 25];%delta angle in degrees
OM2=[25 10 -12];%omega2 in rad/2
AP2=[15 0 5];%alpha 2 in rad/2^2
theta2=theta_2*(pi/180);%convert theta 2 to rad
da=d_a*(pi/180);%convert delta to rad
x_size=3
%%Calculations
for i = 1:x_size
K1=L1(i)/L2(i);
K2=L1(i)/L4(i);
K3=(L2(i)^2-L3(i)^2+L4(i)^2+L1(i)^2)/(2*L2(i)*L4(i));
K4=L1(i)/L3(i);
K5=(L4(i)^2-L1(i)^2-L2(i)^2-L3(i)^2)/(2*L2(i)*L3(i));
A=cos(theta2(i))-K1-K2*cos(theta2(i))+K3;
B=-2*sin(theta2(i));
C=K1-(K2+1)*cos(theta2(i))+K3;
D=cos(theta2(i))-K1+K4*cos(theta2(i))+K5;
E=-2*sin(theta2(i));
F=K1+(K4-1)*cos(theta2(i))+K5;
end
Here is my code and the data I am trying to use. I want to solve for K1-K5 and A-F for p#1-14. I have attempted to do only a sample and then the first two rows of data but I can only get it to solve for the sample data and it wont calculate for the first two rows. I thought I should use the x_size but it is not working. Can someone please help me to figure out how I can get my code to run for all of the data points?

採用された回答

Walter Roberson
Walter Roberson 2021 年 11 月 8 日
clear
clc
close all
%%Given Information
L1=[100 6 7];
L2=[40 2 9];
L3=[120 7 3];
L4=[80 9 8];
theta_2=[40 30 85];%theta2 in degrees
OC=[1 1 2];%1 for open 2 for crossed
rp=[0 6 9];
d_a=[0 30 25];%delta angle in degrees
OM2=[25 10 -12];%omega2 in rad/2
AP2=[15 0 5];%alpha 2 in rad/2^2
theta2=theta_2*(pi/180);%convert theta 2 to rad
da=d_a*(pi/180);%convert delta to rad
x_size=3
x_size = 3
%%Calculations
for i = 1:x_size
K1=L1(i)/L2(i);
K2=L1(i)/L4(i);
K3=(L2(i)^2-L3(i)^2+L4(i)^2+L1(i)^2)/(2*L2(i)*L4(i));
K4=L1(i)/L3(i);
K5=(L4(i)^2-L1(i)^2-L2(i)^2-L3(i)^2)/(2*L2(i)*L3(i));
A(i)=cos(theta2(i))-K1-K2*cos(theta2(i))+K3;
B(i)=-2*sin(theta2(i));
C(i)=K1-(K2+1)*cos(theta2(i))+K3;
D(i)=cos(theta2(i))-K1+K4*cos(theta2(i))+K5;
E(i)=-2*sin(theta2(i));
F(i)=K1+(K4-1)*cos(theta2(i))+K5;
end
[A.', B.', C.', D.', E.', F.']
ans = 3×6
-2.1290 -1.2856 1.3389 -3.1373 -1.2856 0.3307 -0.7113 -1.0000 3.5566 -1.6774 -1.0000 2.5906 0.5178 -1.9924 1.8991 -1.8761 -1.9924 -0.4949
  1 件のコメント
JAKE WISNIEWSKI
JAKE WISNIEWSKI 2021 年 11 月 9 日
Thank you so much. This ended up working perfectly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by