error of inline function

5 次查看(过去 30 天)
Mona
Mona 2013-2-14
In this
Sa=[1 2];
Si =[2 3;45;6 7;8 9;15;5 7];
function='exp(-Theta.*(Si(i,:)-Sa));
I want to find the double integration of this function. IN this I_whole is one arrray of NX2 array.
MY code is :
Theta=[18 3.5];
[x,y]=size(I_whole);
for i=1:1:x
for j=1:1:y
Si(i,j)=I_whole(i,j);
temp=inline('exp(-Theta.*(Si(i,:)-Sa))');
f(i,:)=temp;
end
end
Energy=dblquad(f,1,x,1,y);
But I am getting below error:
??? Error using ==> inline.subsref at 14
Not enough inputs to inline function.
Error in ==> dblquad>innerintegral at 73
fcl = intfcn(xmin, y(1), varargin{:}); %evaluate
only to get the class below
Error in ==> quad at 76
y = f(x, varargin{:});
Error in ==> dblquad at 53
Q = quadf(@innerintegral, ymin, ymax, tol, trace,
intfcn, ...

回答(1 个)

Walter Roberson
Walter Roberson 2013-2-14
Do not use inline for that.
I would suggest using anonymous functions, but since all of your expression components have defined values, you have no variable to integrate with respect to. Are you sure you want quadrature integration (which requires a function to integrate) and not the two-dimensional equivalent of trapz() ?
  3 个评论
Mona
Mona 2013-2-15
And I want quadrature integration (which requires a function to integrate).
Walter Roberson
Walter Roberson 2013-2-15
编辑:Walter Roberson 2013-2-15
If you want quadrature integration, you need a function with a free variable to integrate over -- the variable of integration. What is the variable of integration in your expression
exp(-Theta.*(Si(i,:)-Sa))
You have defined specific values for Theta, Si, and Sa, and you are in a "for" loop that defines "i".

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by