when i run the code the plot graphs appears empty here is the code please help to find the mistake i made

조회 수: 1 (최근 30일)
here is the code I used
%calculating velocity
V3 = 10; % velocity of the piston in cm/sec
global c
th2 = pi/6; % initial value for th2
th3 = pi/6; %initial value for th3
c= 28.8:0.2:52.6;
for i = 1:.2:length(C)
c = C(i);
th3 = acos((-1425 - (C(i)).^2)./(110.*C(i)))*(180/pi);
th2 = acos((C(i).^2 - 4625)./(-4400))*(180/pi);
M = [-40*sin(th2) C(i).*sin(th3); 40*cos(th2) -C(i).*cos(th3)];
N = [V3*cos(th3); V3*sin(th3)];
W(:,i) = M\N;
end
W2 = W(1,:);
W3 = W(2,:);
figure;
subplot(2,1,1); plot(th2,W2,'r','linewidth',2);grid
xlabel('{\theta_{2}} [deg]');
ylabel('{\omega_{2}} [rad/sec]');
subplot(2,1,2); plot(th2,W3,'r','linewidth',2);grid
xlabel('{\theta_{2}} [deg]');
ylabel('{\omega_{3}} [rad/sec]');

채택된 답변

Mischa Kim
Mischa Kim 2021년 1월 10일
Seif, I believe this is what you are trying to do:
%calculating velocity
V3 = 10; % velocity of the piston in cm/sec
%global c
th2 = pi/6; % initial value for th2
th3 = pi/6; %initial value for th3
% c= 28.8:0.2:52.6;
C = 28.8:0.2:52.6;
for i = 1:numel(C)
% c = C(i);
th3(i) = acos((-1425 - (C(i)).^2)./(110.*C(i)))*(180/pi);
th2(i) = acos((C(i).^2 - 4625)./(-4400))*(180/pi);
M = [-40*sin(th2(i)) C(i).*sin(th3(i)); 40*cos(th2(i)) -C(i).*cos(th3(i))];
N = [V3*cos(th3(i)); V3*sin(th3(i))];
W(:,i) = M\N;
end
W2 = W(1,:);
W3 = W(2,:);
figure;
subplot(2,1,1); plot(th2,W2,'r','linewidth',2);grid
xlabel('{\theta_{2}} [deg]');
ylabel('{\omega_{2}} [rad/sec]');
subplot(2,1,2); plot(th2,W3,'r','linewidth',2);grid
xlabel('{\theta_{2}} [deg]');
ylabel('{\omega_{3}} [rad/sec]');
Also, I recommend replacing the loop index name i by ii. i is also the imaginary unit in MATLAB.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by