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].

采纳的回答

Ridwan Alam
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 个评论
Heng Zhou
Heng Zhou 2019-12-6
Thanks. So the handling of array of constants is not in solve(), but in symbolic functions (subs). Anyway, it is a way out. Thank you for your prompt answer (PS, fsolve is also a good idea).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by