How to solve an equation with an array of constant parameters?
7 次查看(过去 30 天)
显示 更早的评论
I am trying to solve equation xlogx=e where x is the variable and e is a real constant. e can take many (say 10000) values which are stored in an array e_arr. I want to return an array of numerical solutions with each element corresponding to an element of e_arr. Of course, I can construct a string 'x*log2(x)= - 0.1' for example for each of the element of e_arr, but is there any way to call solve (or vpasolve) function with vector input for the constant parameter e? Could you please help me with this, assuming you are given an array, say, e_arr=[-0.1, -0.54, -0.32, ... ..., -0.79, -0.6]? Thanks a lot. PS: the log function has base 2 and x takes values in [0.0, 1.0].
0 个评论
采纳的回答
Ridwan Alam
2019-12-6
编辑:Ridwan Alam
2019-12-6
syms x e
>> eqns = x*log2(x)==e
eqns =
(x*log(x))/log(2) == e
>> S= solve(eqns,x)
S =
(e*log(2))/lambertw(0, e*log(2))
>> e=[-0.1, -0.54, -0.32, -0.79, -0.6];
>> subs(S)
ans =
[ -log(2)/(10*lambertw(0, -log(2)/10)), -(27*log(2))/(50*lambertw(0, -(27*log(2))/50)), -(8*log(2))/(25*lambertw(0, -(8*log(2))/25)), -(79*log(2))/(100*lambertw(0, -(79*log(2))/100)), -(3*log(2))/(5*lambertw(0, -(3*log(2))/5))]
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!