# MATLAB problem

1. Jun 4, 2012

### zhaniko93

I have such matlab problem: I create variables R1 RF R2 and w so:
Code:
Code (Text):
syms RF R1 R2 w
then I write expression:
Code:
Code (Text):
3*R1*w*(RF + 200)/((R2*w*29*i + 3)*(3*R1*w - 2*i))
which gives:
Code:
Code (Text):
(3*R1*w*(RF + 200))/((3*R1*w - 2*sqrt(-1))*(R2*w*29*sqrt(-1) + 3))
why sqrt(-1) and not i???? furthermore? if I want real part of the expression and write:
Code:
Code (Text):
real(ans)
it gives:
Code:
Code (Text):
3*real((R1*w*(RF + 200))/((3*R1*w - 2*sqrt(-1))*(R2*w*29*sqrt(-1) + 3)))

2. Jun 4, 2012

### gsal

what is it that you don't like about what matlab is doing? Please expand.

What's wrong with sqrt(-1) instead of "i" ... what did you mean with "i"? is it an integer loop variable ? if so, you have not read the basic assumption of matlab i= sqrt(-1)

Also, what's wrong with real(3*complex_number) = 3*real(complex_number) ? I don't see any thing wrong with that.

Remember, it is not a human manipulating your code, it is a computer program that programatically follows certain steps and optimizations to ensure an answer.

3. Jun 5, 2012

### zhaniko93

I want matlab to write my expression of type a/(b+ci)(d+li) to a+bi form and then give b

4. Jun 5, 2012

### rsc42

Have you tried >>vpa(your expression) or >>simplify(collect(your expression,i))? The first will condense all your constants if they're given numerically, whereas the second will organize your symbolic expressions into coefficients of 1 and i (i.e. a and b). Hope that helps.

Rebekah

5. Jun 7, 2012

### zhaniko93

It didn't help :((((

6. Jun 7, 2012

### rsc42

Here's what worked for me just now on matlab 7.14:

>>a=real(collect(3*R1*w*(RF + 200)/((R2*w*29*i + 3)*(3*R1*w - 2*i))))
>>b=imag(collect(3*R1*w*(RF + 200)/((R2*w*29*i + 3)*(3*R1*w - 2*i))))