matlabFunction, using symbolic variables and if statements
Afficher commentaires plus anciens
Hello everybody,
I use the matlabFunction in order to generate a function handle which contains symbolic variables. My problem is that this function handle contains an if- statement, but when generating the function handle and executing it, it gives a wrong result (just 0 or 1 for true or false), is this a bug or what can I do about it?
My function looks like:
if true
% code
end
function [theta] = inverse_kin(l1,l2,pos)
nom = pos(1,:).^2 + pos(2,:).^2 - l1^2 - l2^2;
denom = 2*l1*l2;
theta2 = acos(nom./denom);
alpha = atan2(pos(2,:),pos(1,:));
alpha = (alpha + (alpha<0)*2*pi);
% I could also add an if statement instead like if alpha < 0 then ... else ... but this doesn't work either
nom = pos(1,:).^2 + pos(2,:).^2 + l1^2 - l2^2;
denom = 2*l1*sqrt(pos(1,:).^2 + pos(2,:).^2);
beta = acos(nom./denom);
theta1 = alpha - beta;
theta = [theta1; theta2];
end
pos is a symbolic, and after I do th_fnc = matlabFunction(inverse_kin);
But when executing th_fnc I get wrong results.
Thanks you and best Pascale
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Assumptions dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!