How do i differentiate Euler-Lagrange equation equation?

14 views (last 30 days)
Hamza Yusuf
Hamza Yusuf on 12 Oct 2021
Edited: Hamza Yusuf on 12 Oct 2021
The problem; I am deriving the EOM of a drone with 4motors. I am using this math slides (other papers validate it but this one is concise). In the slides the math is formulated. The problem is when the langarian stated at the end and i have to derivate it.
The lagrange:
The part i am trying to do: because the others i did symbolically on paper(because Matlab not working for me) but this i cannot.
I have found some other solutions evaulating the lagrange of a quadcopter, as seen in:
However i cannot use these solutions because of some controlling i need to do i need to partion my math, they dont. So tried to what he did as seen in my code. So as stated in the slides the lagrange for a quadcopter can be seperated into a rotational and translational-> I will focus on rotational. The says slides that:
becomes
In that this can be defined: (the other terms are from the lagrange. But this is what trying to evalute and this is the C matrix)
Jdot is simply diff(j,t)
N is a roll pitch yaw vector, ndot derivative of N, I (J in code) is a 3x3 inertia tensor. I have tried to evalute the above. I tried to use code archetecture from what i found and it did not work. I am getting wrong output and I think the code i have wrong. After the code I have attached a picture of what the last matrix C in the code should had contained if i did it right. On page 7 on this page is the same output put you can copy it.
Hope I am clear.
clear all
clc;
syms ixx iyy izz t p q r real
syms alp(t) bt(t) gmm(t) x(t) y(t) z(t) J(n) n(t) L(n,ndot)
assumeAlso([alp(t) bt(t) gmm(t) x(t) y(t) z(t) J(n)],'real')
%%
W=[1 0 -sin(alp(t));
0 cos(bt(t)) cos(alp(t))*sin(bt(t));
0 -sin(bt(t)) cos(alp(t))*cos(bt(t))];
Wn=[1 sin(alp(t))*tan(bt(t)) cos(alp(t))*tan(bt(t));
0 cos(alp(t)) -sin(alp(t));
0 sin(alp(t))*sec(bt(t)) sin(alp(t))*sec(bt(t))];
Ji=[ixx 0 0;
0 iyy 0
0 0 izz];
n=[alp(t);bt(t);gmm(t)];
ndot=diff(n,t);
J=transpose(W)*Ji*W;
%% Lagarian:
L=(1/2)*transpose(ndot)*J*ndot;
%% dl/dndot
A=[diff(L,ndot(1));diff(L,ndot(2));diff(L,ndot(3))]
%I solved this part symbolically by hand as it did not work for me in
%matlab
%% d/dt
diff(A,t) % should use chain rule automatically.
%I solved this part symbolically by hand as it did not work for me in
%matlab
%% (1/2)d/dn(ndot^T*J*ndot) (problem here)
a=diff(J,t); %% I know this is correct
b=[(transpose(ndot)*(n(1)));(transpose(ndot)*(n(2)));(transpose(ndot)*(n(3)))]; % error must/could be here
C=a-(1/2)*b
C matrix is a 3x3 where the inputs are stated below i.e C=[C11 C12 C13; C21 etc...]

Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by