Effacer les filtres
Effacer les filtres

Simplifying with respect to trig identities to avoid dividing by zero

3 vues (au cours des 30 derniers jours)
Morten Nissov
Morten Nissov le 27 Fév 2021
Commenté : Morten Nissov le 27 Fév 2021
I need to calculate the jacobian for a set of differential equations and the calculation with respect to one variable is particularly complicated.
A working example
syms x y v a psi omega dt
state = [x; y; v; a; psi; omega];
wt = omega * dt / 2;
hwt = psi + wt;
fx = state + [
(v*dt + 0.5*a*dt^2)*cos(hwt)*usinc(wt) + a*dt/omega*sin(hwt)*(cos(wt) - usinc(wt));
(v*dt + 0.5*a*dt^2)*sin(hwt)*usinc(wt) + a*dt/omega*cos(hwt)*(usinc(wt) - cos(wt));
a * dt;
0;
omega * dt;
0
];
dfx_domega = diff(fx(1), omega); % this is the derivative to be simplified
function [ y ] = usinc( x )
%un-normalized sinc function
i=find(x==0);
x(i)= 1; % From LS: don't need this is /0 warning is off
y = sin(x)./(x);
y(i) = 1;
end
The problem is that the derivative results in fractions with ω in the denominator. For this case this is the turn rate which can very possibly be zero, as such I would like to manipulate the equations such that it is not in the denominator as far as possible, this is possible in large by applying .
Is there any way I can apply simplify or rewrite such that the fractions are simplified as such?

Réponses (1)

Hernia Baby
Hernia Baby le 27 Fév 2021
How about using logical indexing?
function [ y ] = usinc( x )
y = sin(x)./(x); % y(x==0) => NaN
y(x==0) = 1; % y(x==0) => 1
end
  1 commentaire
Morten Nissov
Morten Nissov le 27 Fév 2021
The usinc function works fine, the problem is the symbolic math produces equations with lots of ω terms in the denominator, which isn't realizable for small values of , which is very typical.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by