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

  • Context: MATLAB 
  • Thread starter Thread starter zhaniko93
  • Start date Start date
  • Tags Tags
    Matlab Rf Variables
Click For Summary

Discussion Overview

The discussion centers around solving MATLAB problems involving symbolic variables R1, RF, R2, and w, particularly focusing on the representation of complex numbers and extracting real and imaginary parts of expressions. Participants explore issues related to MATLAB's handling of these variables and expressions.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant questions why MATLAB uses sqrt(-1) instead of the imaginary unit i in the output of their expression.
  • Another participant suggests that the use of sqrt(-1) is standard in MATLAB, as i is defined as sqrt(-1) and may conflict with other uses in programming.
  • A participant expresses a desire for MATLAB to convert expressions of the form a/(b+ci)(d+li) into a+bi form and extract the imaginary part b.
  • Suggestions are made to use the vpa and simplify functions to help organize and condense expressions in MATLAB.
  • A later reply shares a successful method for extracting the real and imaginary parts of the expression using the collect function.

Areas of Agreement / Disagreement

Participants express differing views on MATLAB's handling of complex numbers, particularly regarding the representation of the imaginary unit. There is no consensus on the best approach to achieve the desired output format.

Contextual Notes

Some participants may have different assumptions about the use of i in MATLAB, which could affect their understanding of the problem. The discussion does not resolve the underlying issues with the symbolic representation and extraction of parts of complex expressions.

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))))
 

Similar threads

Replies
5
Views
2K
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 18 ·
Replies
18
Views
3K
Replies
8
Views
3K
Replies
2
Views
3K