How to find value of function for array of inputs ?

Lets say f(x) is user inputed function and I have some values of x stored in array, Now I have to find the value of the function for each value of x.
i.e, if I have f(x) as x*2 [This is user-input]
then If i have x = [1,3,4,6]
and I need an other array which the value of f(x)
y= [1,9,16,36] as my answer.
Is there any function that will let evalute the same at once ?

답변 (1개)

David Hill
David Hill 2021년 4월 3일
f=@(x)x.^2;
x=[1 3 4 6];
y=f(x);

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 4월 3일

댓글:

2021년 4월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by