Simplifying with respect to trig identities to avoid dividing by zero

조회 수: 2 (최근 30일)
Morten Nissov
Morten Nissov 2021년 2월 27일
댓글: Morten Nissov 2021년 2월 27일
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?

답변 (1개)

Hernia Baby
Hernia Baby 2021년 2월 27일
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
Morten Nissov
Morten Nissov 2021년 2월 27일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by