Challenge

Week 3 - Solving second order ODEs

function [dtheta_dt] = ode_func(t.theta,b,m,g,L)
theta1 = theta(1);
theta2 = theta(2);
%find derivatin of theta1 and theta2
dtheta1_dt = theta2;
dtheta2_dt = -(b/m)*theta2-(g/L)*sind(theta1);
%creating array of dtheta_dt
[dtheta_dt] = [dtheta1_dt; dtheta2_dt];
end 



clear all
close all
clc

%inpute
L =1;
b = 1;
m = 0.05;
g = 9.81;

%time span for penfukam
t_span = linspace(0,20,500);

%initial condition
theta_0 = [0;3]

%solving ode by using ode45
[t,results] = ode45(@(t,theta) ode_func(t,theta,b,m.g.L)t_span,theta_0);

%ploting analaysis pendulam 
plot(t,results(:1))
hold on
xlabel('time')
ylabel('displacment/velocity')
grid on
hold off


ct=1;
for i = 1:length(results(:,1))
    %original or starting possiton of pendulam  are fiexd 
    
    x0 = 0;
    y0 = 0;
    
    %valune of end point of pendulam 
    x1 = L*sin(results(i,1));
    y1 = L*cos(results(i,1));
    
    figure(2)
    hold on
    plot([-1 1][0 0],'linewidth',3);
    plot([x0 x1][y0 y1],'linewidth',4);
    plot(x1 y1,'marker','o','markersize',20,'markerfacecolor','b');
    plot(x1 y1,'marker','o','markersize',20,'markerfacecolor',[1,1,1,]);
    line([x0 x0],[y0 -1.5],'linestyle','--','color','r','linewigth'.3)
    
axis('tight');
pause(0.003);
grid on
text = sprintf('text%d.png',ct);
saveas(gca,text);
clf();
ct = ct+1;
end

solve the two degree eqution from one degree of eqution

theta = theta1

dtheta_dt = dtheta1/dt =theta2

d^2theta/dt^2=d^2theta1/dt^2=dtheta2/dt

by using

dtheta1/dt = theta2

dtheta2/dt=(-b/m)theta2-(g/L)sin(theta)

firstly put all the input

and make function in onther file like( b,L,m,g t,theta)

with ode45 and the solution you return both theta and theta dot.

PART 1: Study how co-contraction influences the stability and position/orientation of the forearm. To do this use three values of co-contraction t and y are innitial conditon and final condtion

t_span as an array wich is eving from 0 to 20 in between given 30 values . using linespae commond

now calling the funtion wiche name ode_funct by using ode45 commond and putting all value which are neede to complet the line of programm

.

animation

firstly counter team using for making aniation commond ct = 1

given staring point of animation x0 = 0 and y0 = 0

using formula

https://youtu.be/Q5Nx8HJqYzU

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.