MATLAB Answers


How do I find what y equals from an equation?

Asked by Warm Cup on 6 Jun 2019
Latest activity Commented on by Warm Cup on 6 Jun 2019
Hi, I'm trying to solve an equation to get the answer of y. I used this code to help me find y, but got this error (Error in Untitled2 (line 22)
eqn = ((e1/(ex(y^2-e1*ko^2)^0.5))+i(sigma/(2*(pi)*w0*ex*eo)))*(y^2*(ex/ez)-ex*ko^2)^0.5 ==
The original equation should look like the equation in the image, but changed some variables to simpler ones (eg: gamma is y here).
Note: coth here is the Hyperbolic Cotangent.Capture.PNG
q= 1.6*10^-19;
kb= 1.38*10^-23;
T= 298;
Vf= 10^6;
hev= 6.582*10^-16;
kbev= 8.6*10^-5;
tio= 6*10^-12;
h= 1.055*10^-34;
w0= 113126*10^7;
n0= 10^15;
e1= 8.85*10^-12;
eo= 8.85*10^-12;
ex= 42.3;
ez= 25;
mio1= hev*Vf*(pi*n0)^.5;
d= 80*10^-9;
ko= 2*pi/1665*10^-9
sigma= i*q^2*kb*T*(mio1/(kbev*T)+2*log(exp(-mio1/(kbev*T))+1))/(pi*h^2*(w0+i/tio));
syms y
eqn = ((e1/(ex(y^2-e1*ko^2)^0.5))+i(sigma/(2*(pi)*w0*ex*eo)))*(y^2*(ex/ez)-ex*ko^2)^0.5 == -coth((d/2)*(y^2*(ex/ez)-ex*ko^2)^0.5);
soly = solve(eqn, y)


Sign in to comment.



1 Answer

Answer by John D'Errico
on 6 Jun 2019
 Accepted Answer

First, when you have a question about an error, report the entire error, that which is written in red in the command window.
When I try to execute the code you supply, I get this:
eqn = ((e1/(ex(y^2-e1*ko^2)^0.5))+i(sigma/(2*(pi)*w0*ex*eo)))*(y^2*(ex/ez)-ex*ko^2)^0.5 == -coth((d/2)*(y^2*(ex/ez)-ex*ko^2)^0.5);
Error using sym/subsindex (line 845)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must
be sym expression.
That pushes me to read the line of code that failed. You should learn MATLAB syntax.
Is "i" a function? No. It is the imaginary constant, sqrt(-1).
When you write this i(stuff), MATLAB assumes that you have defined a function called i. So you get an errror, because i is a variable.
The same thing applies to ex, where you failed to provide an operator. This line executes without an error now.
eqn = ((e1/(ex*(y^2-e1*ko^2)^0.5))+i*(sigma/(2*(pi)*w0*ex*eo)))*(y^2*(ex/ez)-ex*ko^2)^0.5 == -coth((d/2)*(y^2*(ex/ez)-ex*ko^2)^0.5);
Of course, you need to know that no analytical solutiobn to your problem can exist. So solve will give up and use a numerical solver - vpasolve. And vpasolve, with the default strting value, may or may not find the solution that you want to see.
Anyway, the garbage answer that solve/vpasolve does find...
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
> In solve (line 304)
ans =
- 2832015.543898071889729601355261711441252 - 209003.8218923036774138338517475746314398i
That is clearly in the wees, since if a solution does exist, I might expect it to be on the order of 1e-10 or so, just by looking at your expression.
2 / 2.0922e-13 \ 2
sqrt(1.692 y - 6.0238e-22) | --------------------- - 1.8257e-6 + 2.6898e-7i | == -coth(4.0e-8 sqrt(1.692 y - 6.0238e-22)) 1.0
| 2 |
\ sqrt(y - 1.2603e-34) /
So before you do anything, you SHOULD plot your function. First, re-write it as:
eqn = ((e1/(ex*(y^2-e1*ko^2)^0.5))+i*(sigma/(2*(pi)*w0*ex*eo)))*(y^2*(ex/ez)-ex*ko^2)^0.5 - (-coth((d/2)*(y^2*(ex/ez)-ex*ko^2)^0.5));
I predict you will find there are problems with this expression, in terms of finding a solution.

  1 Comment

Thank you for the answer. I will revise the expression, and will try to simplify it more.

Sign in to comment.