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

 채택된 답변

dpb
dpb 2017년 7월 30일

0 개 추천

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;
...
Only beta in the loop is dependent upon i but nothing in the subsequent calculation is dependent upon beta; A and b are invariant so the result will be.
Whatever it is in A that you wish to be changing has to be in the loop and then referenced in either A and/or b to have any effect. Not sure what that is intended to be but that's where the problem lies....

댓글 수: 1

JS
JS 2017년 7월 31일
Thank you very much.
I have to more study about Matlab :D
Have a nice day!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 프로그래밍에 대해 자세히 알아보기

질문:

JS
2017년 7월 30일

댓글:

JS
2017년 7월 31일

Community Treasure Hunt

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

Start Hunting!