I want to create a function handle to the function:
f = @(x) (x-1)*(x-2)*...*(x-50);
How can I do this in MATLAB without typing all 50 terms?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is a vectorized solution:
Or if you want an anonymous function:
By the way, it might not be faster than @Chris solution (which is good, and I upvoted it), because of Matlab JIT-Accelerator.