MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Pieter
on 20 May 2013

Good day,

At the moment I have got equations which look like:

A = ....- q1^2*q1c*q3c + q1*q3*q1c^2 - q1*q3*q2c^2 - q1*q3*q3c^2 + q1*q3*q4c^2 - 2*q1*q4*q1c*q2c - 2*q1*q4*q3c*q4c - q2^2*q1c*q3c + q2^2*q2c*q4c + 2*q2*q3*q1c*q2c + 2*q2*q3*q3c*q4c + q2*q4*q1c^2 - q2*q4*q2c^2 - q2*q4*q3c^2 + q2*q4*q4c^2 + q3^2*q1c*q3c - q3^2*q2c*q4c + q4^2*q1c*q3c - q4^2*q2c*q4c))/((q1*q1c + q2*q2c + q3*q3c + q4*q4c)*(q1^2 + q2^2 + q3^2 + q4^2)*(q1c^2 + q2c^2 + q3c^2 + q4c^2))

Now I know that:

q1c^2+q2c^2+q3c^2+q4c^2 = 1 q1^2+q2^2+q3^2+q4^2 = 1

I like to introduce this information such that I can work with more simplified expressions, because the ones I work with at the moment are very large.

Any ideas how I can achieve this?

Answer by Walter Roberson
on 20 May 2013

simplify(subs(A, {q4c^2, q4^2}, {1 - (q1c^2+q2c^2+q3c^2), 1 - (q1^2+q2^2+q3^2)}))

## 2 Comments

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76434#comment_149971

If q1c^2+q2c^2+q3c^3+q4c^4 = 1 then what would you like (q1^2 + q2^2 + q3^2 + q4^2) to be transformed to?

Will the expression q1c^2+q2c^2+q3c^3+q4c^4 appear specifically as a sub-expression, or do you need to (for example) have MuPAD detect that

is

and so substitute

which is

?

## Pieter (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76434#comment_149992

I am sorry, I made an error in my question, what I know is that:

So I simply want that (q1^2 + q2^2 + q3^2 + q4^2) becomes 1 (that is much simpler, right).

Furthermore, I would like that (1-q1c^2-q2c^2-q3c^2) is replaced by q4c^2 and so on.

So to summarise, I would like to use the information I have (q1c^2+q2c^2+q3c^2+q4c^2 = 1 and q1^2+q2^2+q3^2+q4^2 = 1) to simplify the very long expressions as much as possible.

P.S. I have updated my question now.