Challenge

Week 4.1 - Solving second order ODEs

clear all

close all

clc

b=0.01;

g=9.81;

l=1;

m=0.1;

% initial condition

theta_0 = [0;5];

% time points

t_span = linspace(0,10,500);

% slove ODE

[t, results] = ode45(@(t,theta) ode_func(t, theta, b,g,l,m)t_span, theta_0)

plot(t,results(:,1))

hold on

plot(t,results(:,2))

xlabel('time')

ylabel('plot')

explanasion:

# commands write as clear all,close all,clc its basic of write a every basics of program write in matlab

# after give the basic valuses of input

damping_coefficent (b) = 0.01;

gravity(g) = 9.81;

lenth of pendulam(l) = 1;

mass(m) = 0.1;

# diffind initial conditionthere are 2 first order ODE'S

# 1st ode_function vlocity_displacemnt write as

% initial condition

theta_0 = [0;5];

# 2nd ode_function time to travling distance

% time points

t_span = linspace(0,10,500);

# slove ODE

[t, results] = ode45(@(t,theta) ode_func(t, theta, b,g,l,m),t_span, theta_0);

# ode_function write as

functrion [dtheta_dt] = ode_function(t,theta,b,g,l,m)

theta1 = theta(1)

theta2 = theta(2)

dtheta1_dt = theta2;

dtheta2_dt = -(b/m)*theta2 - (g/l)*sin(theta1); {d^2theta/dt^2+b/m dtheta/dt+g/l sintheta = 0}

end

# slove 2 ODES results

1st ode result

plot(t,results(:,1))

2nd ode result

plot(t,results(:,2))

# applying grid by using

hlod on

# finally applying Axis x,y names

xlabel('time')

ylabel('plot')

# save program and run

give the figure of the time & plot reading volums on the display of figure

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.