Howto remove complex expressions in syms

4 次查看(过去 30 天)
I have the following example code:
clear all; clc; close all;
syms q1 q2 q3 q4 q5 q6;
assume(q1,'positive'); assumeAlso(q1,'real');
assume(q2,'positive'); assumeAlso(q2,'real');
assume(q3,'positive'); assumeAlso(q3,'real');
assume(q4,'positive'); assumeAlso(q4,'real');
assume(q5,'positive'); assumeAlso(q5,'real');
assume(q6,'positive'); assumeAlso(q6,'real');
syms l1 l2 l3 l4;
assume(l1,'positive'); assumeAlso(l1,'real');
assume(l2,'positive'); assumeAlso(l2,'real');
assume(l3,'positive'); assumeAlso(l3,'real');
assume(l4,'positive'); assumeAlso(l4,'real');
result = -angle(-(sin(q6) + cos(q6)*1i)*(cos(q2 + q3 + q4)*cos(q1) - cos(q5)*sin(q1)*1i + sin(q2 + q3 + q4)*cos(q1)*sin(q5)*1i)*1i)
How can I change the expression into an algebraic form without complex numbers?
EDIT:
I created a better example to show my problem (thank you for simpler representation, madhan ravi):
clear all; clc; close all;
syms q1 q2 q3 q4 q5 q6 l1 l2 l3 l4 real
assume([q1 q2 q3 q4 q5 q6 l1 l2 l3 l4],'positive')
%No complex numbers:
B1 = -atan2(- cos(q6)*(cos(q5)*sin(q1) - sin(q2 + q3 + q4)*cos(q1)*sin(q5)) - cos(q2 + q3 + q4)*cos(q1)*sin(q6), cos(q2 + q3 + q4)*cos(q1)*cos(q6) - sin(q6)*(cos(q5)*sin(q1) - sin(q2 + q3 + q4)*cos(q1)*sin(q5)))
cos(B1) %complex numbers suddenly appear here
simplify(B1) %here also
I suspect that these complex numbers were inserted during simplification steps. Can they be removed again?

回答(1 个)

madhan ravi
madhan ravi 2019-1-2
编辑:madhan ravi 2019-1-2
When you substitute a number you would also a get a complex number because you multiply with imaginary number i , how would you mean to eliminate them?
syms q1 q2 q3 q4 q5 q6 l1 l2 l3 l4 real
assume([q1 q2 q3 q4 q5 q6 l1 l2 l3 l4],'positive')
result = -angle(-(sin(q6) + cos(q6)*1i)*(cos(q2 + q3 + q4)*cos(q1) - cos(q5)*sin(q1)*1i + sin(q2 + q3 + q4)*cos(q1)*sin(q5)*1i)*1i)
  3 个评论
metty
metty 2019-1-2
To calculate the expression, you would not need complex numbers. E.g. angle is an atan2-function where the imaginary and the real part uses. I could substitute this function manually. However, Matlab might have a function that forces that an expression can be transformed in a way that no complex numbers occur anymore.
metty
metty 2019-1-2
I updated my question. I think it's easier to explain it this way.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by