What am i doing wrong? This expression is violating basic Mathematics.
이전 댓글 표시
If you run this code, you will get
SI(1,1) = -1 [SI is the sine term of the main formula mentioned below]
sqroot(1,1) = 0.0026
MI = 0.0026
Hence, according to %Main Formula
pos1(1,1) = 0.0026 + 0.0026*(-1) = 0
But the answer matlab is returning me is 0.002
How is this even possible?
Is there any error in the for loop?
%Defining values of parameters
Fg = 2.1188;
Fi = 2.7834;
Ft = Fg + Fi;
h = 0.002;
k = 1864;
e = 0.7;
m = 0.001;
% Initializing for x
x = zeros(11,1);
x(1,1) = 0;
l = 0.002;
%Formula 1 - determining new positions
for i = 1:10
con1 = ((Ft*h)-(k*(h^2)*0.5))*(1-(e^2));
x(i+1,1) = (Ft-(sqrt((Ft^2)-(2*k*((con1)+((e^2)*(Ft*x(i,1)-(k*0.5*(x(i,1)^2)))))))))/k;
end
%Initializing for constants N & S
N = zeros(10,1);
S = zeros(10,1);
W = (2*Ft)/m;
%Calculating constants N & S
for i = 1:10
S(i) = (((W*l)-((k*(l^2))/m))*((e^2-1))-((e^2)*(x(i,1))*(W+((k*(x(i,1)))/m))));
end
sininv = zeros(10,1);
sqroot = zeros(10,1);
pos1 = zeros(5000,1);
pos2 = zeros(5000,1);
time = zeros(5000,1);
M = 2*Ft;
time(1,1) = 0;
for i = 1:10
N(i,1) = ((k*((x(i,1))^2)) - (2*Ft*(x(i,1))));
sininv(i,1) = asin((x(i,1)-(M/2*k))/(sqrt(((M/2*k)^2)+(N(i,1)/k))));
sqroot(i,1) = sqrt((((M/(2*k))^2)+(N(i,1)/k)));
for j = 1:5000
time(j+1,1) = time(j,1)+0.0001;
%Formula 2 - pos1
SI = (sin(((sqrt(k/m))*time(1,1))+sininv(1,1)));
MI = M/(2*k);
%MAIN FORMULA
pos1(j,1) = MI+(sqroot(i,1))*(sin(((sqrt(k/m))*time(j,1))+sininv(i,1)));
end
end
댓글 수: 2
Walter Roberson
2020년 5월 12일
SI = (sin(((sqrt(k/m))*time(1,1))+sininv(1,1)));
Why are you calculating SI there? You do not use the value
time(j+1,1) = time(j,1)+0.0001;
It would be easier to go before the loops and define
time = (0:4999).' * 0.0001;
Sandip Ghatge
2020년 5월 12일
채택된 답변
추가 답변 (1개)
Cris LaPierre
2020년 5월 12일
편집: Cris LaPierre
2020년 5월 12일
0 개 추천
Nothing is wrong with your equation. However, think through your code. The nested for-loops are messing up your logic. The variable pos1 gets overwritten everytime the outerloop increments. You are checking the value of pos1(1,1) once your code has finished executing. That means you should be checking the math using sqroot(i,1) where i=10 (last value of outer loop counter).
SI(1,1) = -1
sqroot(10,1) = 0.0006
MI = 0.0026
pos1(1,1) = 0.0026 + 0.0006*(-1) = 0.002
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!