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

In summary, the conversation is about a user's difficulty in getting MATLAB to write an algebraic expression in the form of a+bi. They had trouble understanding why the program used "sqrt(-1)" instead of "i" and why it didn't give the desired output when using the "real" function. Another user suggests using the "vpa" and "collect" functions to simplify and organize the expression into coefficients of 1 and "i". The summary also includes an example of how the functions were used successfully.
  • #1
zhaniko93
13
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
  • #2
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
I want MATLAB to write my expression of type a/(b+ci)(d+li) to a+bi form and then give b
 
  • #4
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
It didn't help :((((
 
  • #6
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))))
 

What is MATLAB?

MATLAB is a programming language and software environment used for numerical computation, data analysis, and algorithm development. It is commonly used in engineering, science, and mathematics fields.

What are R1, RF, R2, and w variables in MATLAB?

R1, RF, R2, and w are variables used in MATLAB for solving electrical circuit problems. R1 and R2 represent the resistance values of two different resistors, RF represents the feedback resistance, and w represents the angular frequency.

How do I solve MATLAB problems using R1, RF, R2, and w variables?

To solve MATLAB problems using these variables, you can use the built-in functions and operators in MATLAB, such as the resistor function for R1 and R2, and the multiplication operator for RF and w. You can also use the symbolic math toolbox for more complex calculations.

Can I use other variables besides R1, RF, R2, and w in MATLAB?

Yes, you can use any variable name you want in MATLAB as long as it follows the naming rules and conventions. However, using R1, RF, R2, and w can make your code more readable and easier to understand for others.

Are there any tips for efficiently solving MATLAB problems with R1, RF, R2, and w variables?

Some tips for efficiently solving MATLAB problems with these variables include properly defining the variables and their values, using comments to explain your code, and breaking down complex problems into smaller, manageable steps. It is also helpful to practice and familiarize yourself with MATLAB's built-in functions and syntax.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
5
Views
904
  • Engineering and Comp Sci Homework Help
Replies
18
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Introductory Physics Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
Back
Top