필터 지우기
필터 지우기

Need help using same equation for multiple data points.

조회 수: 3 (최근 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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by