Simplifying with respect to trig identities to avoid dividing by zero
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposte (1)
Hernia Baby
il 27 Feb 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
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!