Simplifying with respect to trig identities to avoid dividing by zero

8 visualizaciones (últimos 30 días)
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?

Respuestas (1)

Hernia Baby
Hernia Baby el 27 de Feb. de 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 comentario
Morten Nissov
Morten Nissov el 27 de Feb. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by