problem about inner product of function

조회 수: 13 (최근 30일)
Chongqing Fan
Chongqing Fan 2016년 6월 10일
댓글: Walter Roberson 2016년 6월 10일
Frist, Thanks for your attention for my question, the following is my code:
% code
function responsenum = numreponse(num)
switch num
case 1
response = @(x,y)x+y;
case 2
response = @(x,y)x*y;
function y = innerprod(fun1,fun2)
y = fun1.*fun2;
psi = dblquad(innerprod(numreponse(1),numreponse(2)),-1,1,-1,1,1e-2,@quad1)
when i run the code, the error message is "undefined function 'times' for input arguments of type 'function_handle'" . i will be appreciated if you can give me a help!ThKs

채택된 답변

Walter Roberson
Walter Roberson 2016년 6월 10일
function y = innerprod(fun1,fun2)
y = @(x,y) fun1(x,y) .* fun2(x,y);
  댓글 수: 2
Chongqing Fan
Chongqing Fan 2016년 6월 10일
Dear Walter,
Thank you so much for your answer, it works! when the fun1 and fun2 is constant, this code is not work, could you give me some advice, why the below question occurs because i can not fully understand the principle of the MATLAB, could you give me some recommendation or books or website to improve my matlab skill!
All the best,
Chongqing Fan
Walter Roberson
Walter Roberson 2016년 6월 10일
function y = innerprod(fun1,fun2)
if isa(fun1, 'function_handle')
if isa(fun2, 'function_handle')
y = @(x,y) fun1(x,y) .* fun2(x,y);
else
y = @(x,y) fun1(x,y) .* fun2;
end
elseif isa(fun2, 'function_handle')
y = @(x,y) fun1 .* fun2(x,y);
else
y = @(x,y) fun1 .* fun2;
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Communications Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by