Symbolical differentiation of parametric function
Mostrar comentarios más antiguos
Hello! I am trying to compute the symbolic partial derivative of a parametric function I have defined.
I will report here both main and function
C = [-0.016 1.82e-2 5.5e-3 -2.06e-5 5.91e-7];
G = 6.67259e-20;
R_main = 780e-3;
l = 2;
mass_sys = 5.28e11; %[kg] mass of the system
mass_ratio = 0.0093; % mass ratio
mu = 1 / ((1/mass_ratio) + 1);
m_main = (1 - mu) * mass_sys;
syms x y z
U_main_x = diff(@(x, y, z) U_sph_harm(x, y, z, C, G, m_main, R_main, l), x);
function U = U_sph_harm(x, y, z, C, G, M, R, l)
[lambda, phi, r] = cart2sph(x, y, z);
sum_U = 0;
C_count = 1;
for l_count = 1:l
Plm = legendre(2*l, sin(phi));
for m_count = 0:l_count
sum_U = sum_U + (R/r)^(2*l) * C(C_count) * cos(2 * m * lambda) * Plm(2 * m_count);
C_count = C_count + 1;
end
end
U = G * M / r * (1 + sum_U);
I get the following error
Conversion to logical from sym is not possible.
Error in legendre (line 101)
if ~isreal(x) || ischar(x)|| max(abs(x(:))) > 1
Error in U_sph_harm (line 8)
Plm = legendre(2*l, sin(phi));
Error in main_asteroid (line 92)
U_main_x = diff(@(x, y, z) U_sph_harm(x, y, z, C, G, m_main, R_main, l), x);
Error in sym>funchandle2ref (line 1601)
S = x(S{:});
Error in sym>tomupad (line 1514)
x = funchandle2ref(x);
Error in sym (line 332)
S.s = tomupad(x);
Error in sym/privResolveArgs (line 1102)
argout{k} = sym(arg);
Error in sym/diff (line 29)
args = privResolveArgs(S, invars{:});
Error in main_asteroid (line 92)
U_main_x = diff(@(x, y, z) U_sph_harm(x, y, z, C, G, m_main, R_main, l), x);
Could you please help me sort out why?
Thank you!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Call C/C++ from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


