Clear Filters
Clear Filters

Writing a complicated equation in

9 views (last 30 days)
Rebeca Miyar
Rebeca Miyar on 22 Aug 2018
Answered: David Goodmanson on 24 Aug 2018
I'm trying to write a code for the function attached. The only parameter which isn't a constant is h_c. The problem of course is that h_c appears in both sides of the equation. The only mathematical way I found to overcome this problem is by using the Lambert W function, but I'm not sure how to make it work in matlab. Is there a way to write this type of equation and have matlab solve it?
  5 Comments
Torsten
Torsten on 23 Aug 2018
My guess is that "f" stands for frequency, thus should be inside the "cos" function.
Rebeca Miyar
Rebeca Miyar on 23 Aug 2018
the f is for lattice mismatch, and is outside of the cos

Sign in to comment.

Answers (1)

David Goodmanson
David Goodmanson on 24 Aug 2018
Hello Rebeca,
Matlab does have a lambertw function, so you can use it to solve this.
First of all, since b is known, one can solve for x = h_c / b, in which case
x = C*(log(x)+1)
where C is the product of all the factors in front on the rhs of the equation, except not including the b in the numerator.
You didn't say whether C can be of either sign. Plotting both sides of the equation together for various values of C shows that for negative C there is one real solution, and there are no real solutions for 0<=C<1. The two curves are tangent for C=1 at the point x=1. For C>1 there are two real solutions, one with x<1 and one with x>1. You may well have worked out the algebra, and the two solutions are
C = 2; % example
e = exp(1);
f = @(x) C*(log(x)+1);
x1 = (-C)*lambertw( 0,-1/(C*e))
x2 = (-C)*lambertw(-1,-1/(C*e))
x = .1:.001:7;
plot(x,x,x,f(x),x1,f(x1),'o',x2,f(x2),'o')
Two get both solutions you need two branches of the lambertw function, 0 and 1.
For negative C, there is just the one eal solution x1.
To find roots numerically , the solver fzero is available
C = 2;
g = @(x) C*(log(x)+1) - x; % find zeros
e = exp(1);
x1f = fzero(g,[1/e,1])
x2f = fzero(g,[1,2*C^2])
This gives the same results as before. It helps to supply fzero with intervals that contain one root (that way you are sure to get both roots), and for this problem the hardest part was coming up with suitable intervals for x1 and x2. But for many fzero situations the interval is pretty clear.

Community Treasure Hunt

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

Start Hunting!