how can i integrate a function?

조회 수: 1 (최근 30일)
elham kreem
elham kreem 2018년 2월 16일
댓글: elham kreem 2018년 2월 16일
i have this function fun4=@(y)(y.^2 - d1i'*y+d2i)* f1 * exp(-(y-bx).^2./(2*s*tau))
expectfun4=integral(fun4, -2,4,'ArrayValued',true)
but it is not running ; appear this :
| | * _Error using + Matrix dimensions must agree.
Error in @(y)(y.^2-d1i'*y+d2i)*f1*exp(-(y-bx).^2./(2*s*tau))
Error in integralCalc/iterateArrayValued (line 156) fxj = FUN(t(1)).*w(1);
Error in integralCalc/vadapt (line 130) [q,errbnd] = iterateArrayValued(u,tinterval,pathlen);
Error in integralCalc (line 75) [q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88) Q = integralCalc(fun,a,b,opstruct); ****
although i run as the same function but in another fuction
can you help me
thanks
  댓글 수: 3
Torsten
Torsten 2018년 2월 16일
fun4=@(y)(y.^2 - d1i*y+d2i)* f1 .* exp(-(y-bx).^2./(2*s*tau))
if
(y.^2 - d1i*y+d2i)* f1 .* exp(-(y-bx).^2./(2*s*tau))
gives a senseful vector for y being a scalar value.
Best wishes
Torsten.
elham kreem
elham kreem 2018년 2월 16일
i applied this function ; the result is :
fun4=@(y)(y.^2 - d1i'*y + d2i)* f1. * exp(-(y-bx).^2./(2*s*tau))
|
Error: Unexpected MATLAB operator.

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

채택된 답변

Jan
Jan 2018년 2월 16일
As soon as you write the formula a function instead of an anonymous function, you can debug it:
% Create anonymous function to provide parameters:
fun4 = @(y) fun4fcn(y, d1i, d2i, bx, s, tau);
... Call the integrator
% The actual function:
function dy = fun4fcn(y, d1i, d2i, bx, s, tau)
dy = (y .^ 2 - d1i' * y + d2i) * f1 * exp(-(y-bx) .^ 2 ./ (2 * s * tau));
end
Now use the debugger:
dbstop if error
When Matlab stops at the error, you can check the dimensions of the variables. Because there is only one "+" operator, I guess that d2i has an unexpected shape.
  댓글 수: 2
elham kreem
elham kreem 2018년 2월 16일
only on"+" ; is that a problem?
d2i is a vector 50*1
before that
i run this function
fun3=@(y)(y.^2 + 2*d1i'*y.^3+d3i'*y.^2-d1i'*d2i*y)* f1 * exp(-(y-bx).^2./(2*s*tau))
expectfun3=integral(fun3, -2,4,'ArrayValued',true)
it ok and it is run
is fun3 as fun4?
they have the same dimension
elham kreem
elham kreem 2018년 2월 16일
i used d2i' instead of d2i , the function is run . you are right . the problem is in d2i

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Computations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by