Receiving errors. Undefined variables etc

3 次查看(过去 30 天)
Bria Johnson
Bria Johnson 2018-12-9
重新打开: Star Strider 2018-12-10
Hello,
I am creating a code to find the mass of a beam after balancing it. I had 3 weights. Only 2 of 3 weights could be moved to balance the beam. I am having trouble with my code. I will attach my code and the errors below.
clear
clc
m1 = 1;
% mass 1, measured in kilograms.
m2 = 0.5;
% mass 2, measured in kilograms.
m3 = 0.2;
% mass 2, measured in kilograms.
rp = 0.87;
% distance of pivot, measured in meters.
r1 = 0.03;
% constant distance of mass 1, measured in meters.
r2 = [0.587 0.278 0.2 0.59 0.312 0.685 0.67 0.34 0.503 0.50 0.453]';
% distances obtained when moving mass 2.
r3 = [0.1289 0.2065 2.26 1.2 1.931 0.916 1.1 1.975 1.583 1.421 1.5 1.765]';
% distances obtained when moving mass 3.
l = 2.27;
% length of the beam measured in meters.
g = 9.8;
% gravitational constant measured in meters per seconds squared.
G = ones(length(m1), 2);
G(:,2) = m1;
m = G \ m2
rb = (0.5.*l-rp);
b = (m_b/m2).*rb-(m1/m2).*rb;
m_b =(m2/rp).*b *((-m1)/(rp));
sigma = sqrt(sum((m2-G*m).^2)./(length(m1)-2));
se1 = sigma.*sqrt(1./((length(m1)+mean(m1)^2/((length(m1)-1)*std(m1)^2))));
se2 = sigma.*sqrt(1./((length (m1)-1)*std(m1)^2));
Ci1=tinv(.975,length(m1)-2).*se1;
Ci2=tinv(.975,length(m1)-2).*se2;
% creating a line of best fit
X = [min(m1);1e-3;max(m1)]';
Y = m(1,1) + m(2,1).*X;
SE=sigma.*sqrt(1/length(m1)+(X-mean(m1)).^2./((length(m1)-1)*std(m1).^2));
Ci=tinv(.975,length(m1)-2).*SE;
figure(1)
clf
plot(m1, m2, 'ob')
hold on
% plotting the conidence intervals
plot (X, Y, 'R')
plot(X,Y+Ci,'g--')
plot(X,Y-Ci,'g--')
hold off
xlabel('$$-$$','interpreter','latex')
ylabel('$$-)$$','interpreter','latex')
print(figure(1), '-dpng', 'figure1')
  2 个评论
Star Strider
Star Strider 2018-12-9
You and your classmate seem to be having similar problems!
It would help significantly if you describe the problem you are having, preferably in some detail.
Bria Johnson
Bria Johnson 2018-12-9
The goal is to find the mass of the beam. I am having trouble with all of the variables/componets of the equation for mb. In my code I incorporated the equation for b, which is the y intercept however i am still receiving errors.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by