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일

0 개 추천

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

kman
kman 2017년 10월 31일
Thank you!!
Birdman
Birdman 2017년 10월 31일
If the answer is useful, then accept the answer so that other people having the same problem will know there is a working solution.
Stephen23
Stephen23 2017년 10월 31일
Note that using evalin or eval is not recommended for using with symbolic equations, no matter how much beginners think they are and recommend them to each other. The correct operations are described in the MATLAB documentation: double, subs, or vpa. Symbolic language is not quite the same as MATLAB language, and using eval or evalin is simply the wrong tool for the task.
Read this comment from Steven Lord:
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개)

질문:

2017년 10월 31일

댓글:

2017년 10월 31일

Community Treasure Hunt

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

Start Hunting!