Writing a complicated equation in
18 次查看(过去 30 天)
显示 更早的评论
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 个评论
Torsten
2018-8-23
My guess is that "f" stands for frequency, thus should be inside the "cos" function.
回答(1 个)
David Goodmanson
2018-8-24
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!