Error while mutliplying functions.

조회 수: 10 (최근 30일)
Daniel Caliari
Daniel Caliari 2017년 1월 21일
댓글: Daniel Caliari 2017년 1월 21일
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