Troubleshooting Complex Number Formulas in Matlab

In summary, the speaker is discussing a problem they encounter with complex numbers in Matlab. They have noticed that when writing the same formula in different forms, they get different results. They always check for equality and believe the formulas are mathematically the same. However, they have not been able to find the source of the problem. The other person suggests that the issue could be related to multi-valued complex map operations like taking the logarithm. They also mention that the attached file contains two formulas that give different numerical values. The speaker admits that the expressions are complicated and they have not checked them thoroughly, but they do not see any obvious mistakes. They suggest using a computer algebra system like Mathematica for troubleshooting.
  • #1
hokhani
483
8
One problem I sometimes encounter is with complex numbers. When a formula including functions of complex variables runs in Matlab, I obtain the corresponding result but if I write that formula in different forms (for example when I arrange the long formula in simpler form) I obtain another result. I always check the equality of these formulas and I am confident that they are mathematically the same. I haven't found yet the source of this problem.
 
Physics news on Phys.org
  • #2
It is difficult to troubleshoot without any specific examples - could you perhaps provide one such instance? Sometimes these issues arise when you perform certain multi-valued complex map operations such as taking the logarithm. In these instances, there may be non-equivalence because these software are automatically programmed to take the principal branch.
 
  • #3
In the attached file I have written the two same formulae which give different values numerically.
 

Attachments

  • Matlab Complex Numbers.pdf
    74.9 KB · Views: 217
  • #4
These expressions are hideous. I haven't checked the algebra, but I'm just going to assume they're correct for now. At first glance, I don't think I see anything that could likely cause the issue (unless [itex]q_{I}[/itex] and [itex]q_{II}[/itex] are some funny functions). Especially as the expressions are so ugly, might it have been possible that you've made a small mistake in the code somewhere?
Computer algebra systems like Mathematica would probably help greatly in the troubleshooting as well, since you can trace both the numerics and analytical forms at the same time.
 

Related to Troubleshooting Complex Number Formulas in Matlab

1. What are complex numbers?

Complex numbers are numbers that contain two parts - a real part and an imaginary part. They are represented in the form a + bi, where a is the real part and bi is the imaginary part multiplied by the imaginary unit i.

2. What is the problem with complex numbers?

The main problem with complex numbers is that they do not follow the same rules as real numbers. For example, the commutative and associative properties do not always hold true for complex numbers. This can make calculations and equations involving complex numbers more complex and difficult to solve.

3. How are complex numbers used in science?

Complex numbers are used in various fields of science, such as physics, engineering, and mathematics. They are particularly useful in electrical engineering, where they are used to represent and analyze alternating current circuits.

4. Can complex numbers have a physical meaning?

While complex numbers do not have a direct physical meaning, they can be used to represent physical quantities such as electrical impedance, which is important in the study of electrical circuits. They are also used in quantum mechanics to represent the wave function of particles.

5. How do you add and multiply complex numbers?

To add complex numbers, you simply add the real parts together and the imaginary parts together. To multiply complex numbers, you use the distributive property and then simplify the result, remembering that i squared equals -1. There are also other rules and properties for complex number operations that can be used to simplify calculations.

Similar threads

  • Precalculus Mathematics Homework Help
Replies
12
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Replies
13
Views
2K
  • Differential Equations
Replies
3
Views
2K
  • Precalculus Mathematics Homework Help
Replies
21
Views
841
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • STEM Academic Advising
Replies
18
Views
2K
Replies
1
Views
801
Back
Top