Error while mutliplying functions.

10 次查看(过去 30 天)
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?

采纳的回答

Stephen23
Stephen23 2017-1-21
编辑:Stephen23 2017-1-21
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
  1 个评论
Daniel Caliari
Daniel Caliari 2017-1-21
I thought It would work same way the symbolic notation and that was my mistake.
Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by