Error while mutliplying functions.
10 views (last 30 days)
Show older comments
Daniel Caliari
on 21 Jan 2017
Commented: Daniel Caliari
on 21 Jan 2017
I'm trying to multiply these functions:
a = x^2
b = x
Obviously, It should give me: x^3
But when I write the code:
a = @(x)x^2;
b = @(x)x;
c = a*b;
I got the error: Undefined operator '*' for input arguments of type 'function_handle'.
What am I doing wrong?
0 Comments
Accepted Answer
Stephen23
on 21 Jan 2017
Edited: Stephen23
on 21 Jan 2017
You cannot multiply function handles. You can either:
1) evaluate the function handles for some value/s, and multiply their outputs:
>> a(2).*b(2)
ans =
8
2) create a new function (which can be evaluated later):
>> c = @(x)a(x).*b(x);
>> c(2)
ans =
8
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!