作者hbkhhhdx2006 (比格踢)
看板MATLAB
标题[问题] 建立function求积分
时间Wed Dec 10 02:12:09 2014
Create a function that can do the following things:
Calculate the following integration :
g(k) = ∫f(x)*sin(k*x) dx, where f(x) is any mathematical function, and
the integration range is from -X to X
k=[0: 2*pi/X : 1/dx]
以上是题目
f(x)和上下线都由使用者输入
然後下面是我打的程式码
function onetwothree(f,X)
dx = 1e-6;
for k=0 : 2*pi/X : 1/dx
g = integral(f*sin(k),-X,X);
fprintf('g(%d)=%d\n',k,g);
end
然後去测试 onetwothree(@(x)x^2,1)
结果跑出来这样
Undefined function 'mtimes' for input arguments of type 'function_handle'.
想请问大大我的程式码问题出在哪
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 27.147.50.151
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MATLAB/M.1418148733.A.244.html
1F:推 winnie4952: onetwothree(@(x,k) x.^2*sin(k),1) 12/12 16:34
2F:→ winnie4952: (function里) g=integral(@(x)f(x,k),-X,X) 12/12 16:35
3F:→ winnie4952: 答案不知道对不对 有值就是了 12/12 16:36