input variable in evalin

1 回表示 (過去 30 日間)
kman
kman 2017 年 10 月 31 日
コメント済み: Walter Roberson 2017 年 10 月 31 日
y=double(evalin(symengine, 'binomial(2634,1)*binomial(1360*125-2634, 125-1)/binomial(1360*125, 125)'))
The above gives sume number y. but instead of 1 I want variable x in the above equation.
function y=f(x)
y=double(evalin(symengine, 'binomial(2634,x)*binomial(1360*125-2634, 125-x)/binomial(1360*125, 125)'))
end
Of course this gives an error. How can I make function using the input variable x? Thank you.

採用された回答

Birdman
Birdman 2017 年 10 月 31 日
x=sym('x');
y=evalin(symengine, 'binomial(2634,x)*binomial(1360*125-2634, 125-x)/binomial(1360*125, 125)','x');
y=double(vpa(subs(y,x,1)))
  5 件のコメント
Birdman
Birdman 2017 年 10 月 31 日
Hi Stephen,
I did not recommend him to use eval function. Thank you for your attention once more.
Walter Roberson
Walter Roberson 2017 年 10 月 31 日
There are some symbolic tasks that still need evalin(symengine) or feval(symengine), but those are somewhat advanced tasks.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!