Eulers for two degree spring system
이전 댓글 표시

Hi there, I have to use basic Euler's to find and plot solutions to x1 and x2 over 0 < t < 30 where my step size is 0.001 with initial conditions: my conditions are x1(0) = 5, x2(0) = 1, v1(0) = 0,
Firstly I have multiplied the matrix attached out, subbed in v for x' and rearranged for x'' and renamed it as dv/dt where m = 1 c = 1 k = 2
i have obtained: dv/dt = 1 - (4(x1) - 2(x2)) - (2(v1) - (v2))
dv/dt = 1 - (4(x2) - 2(x1)) - (2(v2) - (v1))
I then tried to implement Euler's for the first equation on matlab t=zeros(30000,0); y=zeros(30000,0);
t(0)=0; x(0)=5; v(0)=0;
for i=1:30000
t(i+1)= t(i)+0.001;
x(i+1)= x(i)+0.001.*(1-(4*x(i)-2*x(i)) -(2*v(i)-v(i));
end
plot(t,x)
I'm getting an error in line 11, unbalances parenthesis and I'm not sure I'm really implementing the scheme correctly so any help would be greatly appreciated!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!