Create a function that evaluates a function handle for a single input.
Create the following function in a file, evaluateHandle.m
, in your working folder.
function evaluateHandle(fh,x)
y = fh(x);
str = func2str(fh);
disp('For input value: ')
disp(x)
disp(['The function ' str ' evaluates to:'])
disp(y)
end
Use a function handle to evaluate the sin
function at pi/2
.
For input value:
1.5708
The function sin evaluates to:
1
Use a function handle to evaluate
for the specified matrix, A
.
For input value:
1 2
0 1
The function @(x)x.^2+7 evaluates to:
8 11
7 8