Filter löschen
Filter löschen

Howto remove complex expressions in syms

1 Ansicht (letzte 30 Tage)
metty
metty am 2 Jan. 2019
Bearbeitet: metty am 2 Jan. 2019
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?

Antworten (1)

madhan ravi
madhan ravi am 2 Jan. 2019
Bearbeitet: madhan ravi am 2 Jan. 2019
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 Kommentare
metty
metty am 2 Jan. 2019
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 am 2 Jan. 2019
I updated my question. I think it's easier to explain it this way.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by