each iteration but same result
이전 댓글 표시
I am trying to do the calculation using the code in for.
In the for statement, the problem arises when calculating the angle beta up to i = 1: N.
The result of Ta0, Fa0, Fa1 and so on comes out, and all values are output equally.
As the value of i changes, the result should be changed.
I do not know why all the output is the same.
Here is i typed code
clear all;
close all;
clc;
i = sqrt(-1);
mu = 0.1;
F = [0,100];
% Link 1(W1)
LP1 = 0.5;
theta = 90*pi/180;
P1 = LP1*exp(i*theta);
P1x = real(P1);
P1y = imag(P1);
% Link 2(V1)
LQ1 = 0.75;
rho = -30*pi/180;
% Slider x axis and y axis
Q1 = LQ1*exp(i*rho);
Q1x = real(Q1);
Q1y = imag(Q1);
% U1 vector
R1 = (P1y+Q1y)*exp(i*theta);
R1y = imag(R1);
% G1 vector
S1 = P1+Q1-R1;
S1x = real(S1);
% crank link assignment
start_angle = 0;
step_angle = 1;
stop_angle = 10;
angle_disp = [start_angle:step_angle:stop_angle]';
N = length(angle_disp);
beta = (angle_disp)*pi/180;
% Link 1
theta = angle(P1);
P = abs(P1);
Px = real(P1);
Py = imag(P1);
% alpha
f_alpha = @(x)[P*cos(theta+beta)+LQ1*cos(rho+x(1))-x(2);
P*sin(theta+beta)+LQ1*sin(rho+x(1))-R1y-0.2248];
options = optimset('Algorithm','Levenberg-Marquardt');
x0 = [0,0];
x = fsolve(f_alpha,x0,options);
alpha = x(1);
g = x(2);
% Link 2
rho = angle(Q1);
Q = LQ1*exp(i*(rho+alpha));
Qx = real(Q);
Qy = imag(Q);
% variables
Ta0 = ones(N,1)*inf;
Fa0 = ones(N,2)*inf;
Fa1 = ones(N,2)*inf;
Fb1 = ones(N,2)*inf;
Fn = ones(N,1)*inf;
Fx = F(1);
Fy = F(2);
for i = 1:1:N
beta = angle_disp(i)*pi/180;
A = [...
0 1 0 1 0 0 0 0
0 0 1 0 1 0 0 0
1 0 0 -Py Px 0 0 0
0 0 0 -1 0 -1 0 0
0 0 0 0 -1 0 -1 0
0 0 0 0 0 Qy -Qx 0
0 0 0 0 0 1 0 mu
0 0 0 0 0 0 1 1];
b=[0;0;0;0;0;0;-Fx;-Fy];
x = A\b;
Ta0(i) = x(1);
Fa0(i,1) = x(2);
Fa0(i,2) = x(3);
Fa1(i,1) = x(4);
Fa1(i,2) = x(5);
Fb1(i,1) = x(6);
Fb1(i,2) = x(7);
Fn(i) = x(8);
end
and result output
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 프로그래밍에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!