フィルターのクリア

Undefined function 'mtimes' for input arguments of type 'function_handle'.

10 ビュー (過去 30 日間)
furkan öksüz
furkan öksüz 2020 年 12 月 15 日
回答済み: Steven Lord 2020 年 12 月 16 日
function [T,I]=fonk(f)
a=-1;
b=1;
y=@(x) f./sqrt(1-x.^2);
I=quad(f,a,b);
k=input('k yi giriniz...');
T=0;
for i=1:k
w=pi./k;
x=cos((2.*i-1).*pi./(2.*k));
h=f;
T=T+w*h;
end
fprintf(' T = %13.10f I= %9.2e\n',T,I)
end
Undefined function 'mtimes' for input arguments
of type 'function_handle'.
Error in fonk (line 12)
T=T+w*h;
what can i do to solve this error?

回答 (2 件)

Daniel Pollard
Daniel Pollard 2020 年 12 月 15 日
Your function fonk takes f as an input. f must be a function handle in order to satisfy the quad requirements. Later, you set h=f and try to calculate w*h. h is a function handle, so this product doesn't make any sense, hence the error you got. In order to rectify this, you must make h be a number, not a function handle. Perhaps you could give the function its arguments, if its output is numeric.
  2 件のコメント
furkan öksüz
furkan öksüz 2020 年 12 月 16 日
編集済み: furkan öksüz 2020 年 12 月 16 日
ı input f and ı run this function. if ı dont use function and ı write this script manually its working. T=T+w*h have a problem in this function. Can ı solve it?
thanks for your answer
Daniel Pollard
Daniel Pollard 2020 年 12 月 16 日
I told you what the problem is and how you can solve it. I can't solve it because I don't know what the function is supposed to do. You need to either change the way it works, or give f an argument.

サインインしてコメントする。


Steven Lord
Steven Lord 2020 年 12 月 16 日
You cannot multiply a number and a function handle or two function handles.
You can multiply a number and the result of evaluating a function handle or the results of evaluating two function handles.
f = @(x) x.^2;
g = @(x) x.^3;
thisWorks1 = 2*f(5)
thisWorks1 = 50
thisWorks2 = f(8)*g(4)
thisWorks2 = 4096
h = @(x) f(x)+g(x);
thisWorks3 = h(3)
thisWorks3 = 36
thisWillNotWork1 = 2*f
Operator '*' is not supported for operands of type 'function_handle'.
thisWillNotWork2 = f*g

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by