Solving a System of 2nd Order Nonlinear ODEs

17 visualizaciones (últimos 30 días)
mpz
mpz el 2 de Abr. de 2022
Comentada: mpz el 3 de Abr. de 2022
Hi, I need help with setting up the code for the below 2 non-linear differential equations. I do not have symbolic toolbox. Below is how I tried it but didn't work. Any help will be appreciated.
clear all;clc
function dydt=mbd(M,m,g,lc,k)
y1=y(1);
y2=y(2);
z1=z(1); %z1
z2=z(2); %z2
y5=(1/(M+m))*((m*l/2)*(sin(z(1)))*y6 + (m*l/2)*(cos(z(1)))*(z(2))^2 ...
-c*y(2)-k*y(1));
y6=(3/(m*l^2))*((m*l/2)*(sin(z(1)))*y5 - (m*g*l/2)*(sin(z(1))));
dydt=[y1;y2;y3;y4;y5;y6];
end

Respuesta aceptada

Sam Chak
Sam Chak el 3 de Abr. de 2022
Hey @mpz
It doesn't work that way because you have created an algebraic loop error where depends y5 that is your , which depends on y6 that is from the beginning.
I'll try to explain how to solve it without using difficult math or matrix operations. Here, the governing equations are given by
Equation 5:
Equation 6:
.
Equation 6 can be rearranged to become
so that it can substituted into Equation 5 to eliminate
and then be simplified to become
... Equation (7).
Note the the right-hand side of Equation 7 does not have the term . Subtituting Equation 7 into the simplified Equation 6 yields
... Equation (8).
Now you can rewrite the mbd ode function in state-space form correctly. Note that the ODEs should have only 4 states (instead of 6 states):
If you find my technical explanation is helpful, please vote and accept the answer.
  9 comentarios
Sam Chak
Sam Chak el 3 de Abr. de 2022
Hi @mpz
Sorry, a little late. The code should look like this. Also thank @Torsten for showing the corrections.
function mpz
close all
clc
tspan = [0 20]; % time span of simulation
y0 = [0.5 pi/3 0 0]; % initial values
[t, y] = ode45(@(t, y) odefcn(t, y), tspan, y0);
plot(t, y, 'linewidth', 1.5)
grid on
xlabel('Time, t [sec]')
ylabel({'$x,\; \theta,\; \dot{x},\; \dot{\theta}$'}, 'Interpreter', 'latex')
title('Time responses of the system states')
legend({'x', '$\theta$', '$\dot{x}$', '$\dot{\theta}$'}, 'Interpreter', 'latex', 'location', 'best')
end
function dydt = odefcn(t, y) % Ordinary Differenctial Equations
dydt = zeros(4,1);
g = 0.2;
M = 2;
m = pi/4;
l = 1;
C = 0.25;
k = 0.5;
dydt(1) = y(3);
dydt(2) = y(4);
dydt(3) = (1/(M + m - (3/4)*(m*(sin(y(2)))^2)))*(((m*l/2)*(cos(y(2))*(y(4))^2)) - ((3/4)*(m*g*((sin(y(2)))^2))) - (C*(y(3))) - (k*(y(1))));
dydt(4) = ((3*sin(y(2)))/(2*l*(M + m - (3/4)*(m*(sin(y(2)))^2))))*(((m*l/2)*(cos(y(2))*(y(4))^2)) - ((3/4)*(m*g*((sin(y(2)))^2))) - (C*(y(3))) - (k*(y(1)))) - ((3*g*sin(y(2)))/(2*l));
end
Result:
mpz
mpz el 3 de Abr. de 2022
Thank you @Sam Chak

Iniciar sesión para comentar.

Más respuestas (1)

Alan Stevens
Alan Stevens el 3 de Abr. de 2022
You haven't passed y and z to the funcion in
function dydt=mbd(M,m,g,lc,k)
Probably needs to be more like
function dydt=mbd(t,y,z,M,m,g,lc,k)
with the calling function modified accordingly.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by