MATLAB Solving MATLAB Problems with R1, RF, R2 and w Variables

AI Thread Summary
The discussion revolves around a MATLAB issue involving symbolic variables and complex numbers. The user encounters unexpected results when performing calculations with variables R1, RF, R2, and w, specifically questioning why MATLAB outputs "sqrt(-1)" instead of "i." It is clarified that in MATLAB, "i" is defined as the imaginary unit, equivalent to "sqrt(-1)." The conversation also addresses the user's desire to extract the real part of a complex expression, leading to confusion over the output format. Suggestions are made to use functions like "vpa" and "simplify" to rearrange the expression into a more manageable form. Ultimately, a solution is provided that successfully separates the real and imaginary parts of the expression using the "collect" function.
zhaniko93
Messages
13
Reaction score
0
I have such MATLAB problem: I create variables R1 RF R2 and w so:
Code:
Code:
syms RF R1 R2 w
then I write expression:
Code:
Code:
3*R1*w*(RF + 200)/((R2*w*29*i + 3)*(3*R1*w - 2*i))
which gives:
Code:
Code:
(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:
real(ans)
it gives:
Code:
Code:
3*real((R1*w*(RF + 200))/((3*R1*w - 2*sqrt(-1))*(R2*w*29*sqrt(-1) + 3)))
can anyone please help me??
 
Physics news on Phys.org
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.
 
I want MATLAB to write my expression of type a/(b+ci)(d+li) to a+bi form and then give b
 
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
 
It didn't help :((((
 
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))))
 
Back
Top