Need help Euler Method
Show older comments
I need help with my code for programming this second order Euler equation. I tried to insert new fuction into the euler code I already had and not sure when im going wrong.
Here is the question:

Here is my code:
% The system of figure shown below consists of a uniform rigid link of
% total mass m and length L, two linear springs of stiffnesses k1 and k2,
% and a viscous damper of damping constant c. When the link is horizontal,
% the springs are unstretched. The motion of the system is described by
% the following second order differential equation:
%
% 1/3mL^2theta2 + k1L^2(1-cos(theta))sin(theta) + k2L^2sin(theta)cos(theta)
% - mgL/2cos(theta) + cL^2(theta1)cos^2(theta) = 0
% Assume:
g = 9.81; % m/s^2
m = 3; % kg
L = 1; % m
k1 = 100; % N/m
k2 = 150; % N/m
c = 1.5; % N*s/m
h = 0.005;
N = 5;
theta(1) = pi/10;
theta1(1) = 0;
for n=1:N
x(n+1) = n*h;
theta(n+1) = theta(n) + h*(1/3*m*L^2*theta2 + k1*L^2*(1-cos(theta))*sin(theta) + k2*L^2*sin(theta)*cos(theta) - m*g*L/2*cos(theta) + c*L^2*(theta1)*(cos(theta))^2) + theta(n);
end
plot(x,theta)
format long
disp (theta)
Not sure what I am doing wrong. Any help would be great. Thank you in advance
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!