필터 지우기
필터 지우기

Howto remove complex expressions in syms

조회 수: 1 (최근 30일)
metty
metty 2019년 1월 2일
편집: metty 2019년 1월 2일
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