Clear Filters
Clear Filters

How do I evaluate a symbolic Jacobian at multiple values of the same variable in the same equation?

85 views (last 30 days)
I am trying to calculate the symbolic Jacobian of a very complicated function, then use the outputs in a separate numerical function by providing inputs with names that match the symbolic variables. A challenge I am running into is that function I am trying to evaluate is built from two different time steps of the same states.
syms L l a r p y Rn Re Li li ai ra pa ya Rei az el azi eli real
where Li, li, ai, ra, pa, ya are second values of the states L, l, a, r, p, y.
%% Transforming from Lla to NED cartesian
E2 = 6.694379990141317e-3; % Eccentricity constant
kappa = 1-E2;
Ce2n = [-sin(L)*cos(l), -sin(L)*sin(l), cos(L); % ECEF to NED DCM
-sin(l), cos(l), 0;
-cos(L)*cos(l), -cos(L)*sin(l), -sin(L)];
p0 = Ce2n*[(Re+a)*cos(L)*cos(l); % platform position NED
(Re+a)*cos(L)*sin(l);
(kappa*Re+a)*sin(L)];
pj = Ce2n*[(Rei+ai).*cos(Li).*cos(li); % emitter positions NED
(Rei+ai).*cos(Li).*sin(li);
(kappa*Rei+ai).*sin(Li)];
%% Create the unit LOS vector
cr = cos(r); sr = sin(r);
cp = cos(p); sp = sin(p);
cy = cos(y); sy = sin(y);
Cb2n0 = [ cp*cy, cp*sy, -sp; ...
-cr*sy + sr*sp*cy, cr*cy + sr*sp*sy, sr*cp; ...
sr*sy + cr*sp*cy, -sr*cy + cr*sp*sy, cr*cp]';
cr2 = cos(ra); sr2 = sin(ra);
cp2 = cos(pa); sp2 = sin(pa);
cy2 = cos(ya); sy2 = sin(ya);
Cb2nj = [ cp2*cy2, cp2*sy2, -sp2; ...
-cr2*sy2 + sr2*sp2*cy2, cr2*cy2 + sr2*sp2*sy2, sr2*cp2; ...
sr2*sy2 + cr2*sp2*cy2, -sr2*cy2 + cr2*sp2*sy2, cr2*cp2]';
u0 = Cb2n0*[cos(az)*cos(el);
sin(az)*cos(el);
sin(el)];
uj = Cb2nj*[cos(azi)*cos(eli);
sin(azi)*cos(eli);
sin(eli)];
%% Trilaterate to initialize feature position
p1 = dot(cross(pj-p0,uj),cross(u0,uj))/((norm(cross(u0,uj))^2));
p2 = dot(cross(p0-pj,u0),cross(uj,u0))/((norm(cross(uj,u0))^2)); % pulled
% from bearings only SLAM for airborne vehicle
feat_pos_n = 1/2*(p0+pj + p1.*u0 + p2.*uj);
feat_pos_g = [L;l;a] + [1/(Rn +a), 0, 0;
0, 1/((Re+a)*cos(L)), 0;
0, 0, -1]*(feat_pos_n-p0); % pulled from Groves
where feat_pos_g is the final symbolic function I need to take the Jacobian of, and it is messy and untractable to perform the Jacobian by hand. I need the function evaluated at L, l, a, r, p, y and Li, li, ai, ra, pa, ya but since the later aren't different states I can't just do
statevect = [r, p, y, L, l, a, ra, pa, ya, Li, li, ai]
because it would differentiate the sets of state values as separate states, and
statevect = [r, p, y, L, l, a]
won't work because any term with the second set of terms won't be differentiated.
Any help would be greatly appreciated.
  7 Comments
Andrew Relyea
Andrew Relyea on 24 Sep 2024 at 12:40
I have not had a chance to try to implement the numerical option you provided, but I think I see how it could be adapted to meet my needs. I will provide an update after I've run some tests.
Umar
Umar on 24 Sep 2024 at 23:58
Hi @Andrew Relyea,
Thank you for your update regarding the numerical option. I appreciate your willingness to explore its potential adaptation to meet your needs. I look forward to hearing about your findings once you have had the opportunity to conduct your tests. Please do not hesitate to reach out if you have any questions or require further assistance during the implementation process.

Sign in to comment.

Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!