Solving a complex equation with all real answers

9 vues (au cours des 30 derniers jours)
Leping Yu
Leping Yu le 28 Mai 2021
Commenté : John D'Errico le 28 Mai 2021
Is there some way to solve a equation with complex numbers in it but all it answers are real numbers in matlab?
For example:
Here both R and C should be real values.

Réponse acceptée

John D'Errico
John D'Errico le 28 Mai 2021
Modifié(e) : John D'Errico le 28 Mai 2021
I hope this is not homework, because it is almost too simple. At the same time, it has an interesting twist. I still fear it is homework. I hope not.
If any solutions do exist, then there will be infinitely many such solutions, since you have one equation with two unknowns. We can think of the general solution locus as an infinite path through the set of complex numbers. And that usually means you can at best solve for one variable in terms of the other.
SO DO SO! Then see if anything interesting happens. The nice thing is this equation is trivially simple to solve. Paper and pencil would suffice, but I am far too lazy, and then there would be no MATLAB context to this question.
syms R C real
eqn = 1/(i + (-50 -25000*R*C*i)/R) == -0.1;
Csol = solve(eqn,C,'returnconditions',true)
Csol = struct with fields:
C: [1×1 sym] parameters: [1×0 sym] conditions: [1×1 sym]
Note that the 'returnconditions' clause is necessary here for a valid solution to the problem.
Csol.C
ans = 
Csol.conditions
ans = 
So, for ANY value of R, we can compute the value of C from R. I guess we can trivially exclude R==0 there also, since then we would have a divide by zero.
The trick is to look carefully at the condition, what does that tell us? Remember that R must be a real number, containing no imaginary part. Therefore, if we know that
R*(1 - 10i) + 50i = R + (50i - 10i*R)
must be a real number, what does that tell us? The second (fully imaginary) part MUST be zero. There is only one case where that can happen, when R = 5, since we know that R MUST be a real number.
Ergo, the unique fully real solution to the problem has R = 5, and we can find the correspondingly unique value of C, as ...
C = subs(Csol.C,R,5)
C = 
No other fully real solution to this particular problem can exist. Other problems may generally be more complicated to solve. Again, could I have done all of this with pencil and paper? Of course.
  3 commentaires
Paul
Paul le 28 Mai 2021
Modifié(e) : Paul le 28 Mai 2021
Why not allow solve() to solve for both R and C simultaneously, with the assumption that R and C are both real?
syms R C real
eqn = 1/(i + (-50 -25000*R*C*i)/R) == -0.1;
sol = solve(eqn,[R C],'ReturnConditions',true);
sol.C
ans = 
sol.R
ans = 
5
Any idea why solve() doesn't apply the real constraints on C and R when solving for Csol, as it appears to do when solving for C and R simultaneously in sol?
John D'Errico
John D'Errico le 28 Mai 2021
Looks like solve did work on both variables at once. I did not try it, since I saw how to solve the problem as I did.
When I told it to solve for C as a function of R, it did exactly as I told it to do - solve for C as a function of R. Then it told us what condition must apply on R for a solution to exist, though it was in a not very simple form. Simplify does not seem to do anything more on the condition when I try it.

Connectez-vous pour commenter.

Plus de réponses (1)

David Hill
David Hill le 28 Mai 2021
syms R C;
eqn=1/(1i+(-50-25000*R*C*1i)/R)==-.1;
r=solve(eqn,R);
c=solve(eqn,C);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by