how can i integral a function which was written in matlab but there is wrong , i dont no where it is :
syms tau
syms y
f= @(y,tau)y*exp(-0.5.*y.^2/ tau)
expecty=integral2(f, -2,4,0,Inf,'auto')

 채택된 답변

Birdman
Birdman 2018년 3월 16일

1 개 추천

integral2 is defined for function handle, therefore you do not need symbolic variables:
f= @(y,tau)y.*exp(-0.5.*y.^2./ tau)
expecty=integral2(f, -2,4,0,Inf,'auto')

댓글 수: 6

elham kreem
elham kreem 2018년 3월 16일
if i use it as a defined , the result is:
expecty =
NaN
Torsten
Torsten 2018년 3월 16일
The result is correct.
Did you expect something finite for the integral ?
elham kreem
elham kreem 2018년 3월 16일
do you mean that :
expecty = nan
is correct?
Steven Lord
Steven Lord 2018년 3월 16일
When y = 0 and tau = 0, you're computing 0.*exp(0./0). 0./0 is NaN, exp(NaN) is NaN, and 0*NaN is NaN. Once NaN enters a calculation, it tends to propagate throughout that calculation.
Torsten
Torsten 2018년 3월 16일
Neglecting numerical aspects like division by 0, your integral is +Inf.
Best wishes
Torsten.
elham kreem
elham kreem 2018년 3월 16일
gentelmen , thanks for your answers , but there is something wrong?
because the result is not convincing .
if i integrate the function with syms y and tau , are the code right and the result?
syms tau
syms y
fun = @(y,tau) (1/tau) * y * exp((-0.5*y^2 / tau)
f1 = int(fun , y ,tau )
is this mean double integral , for y and tau?
the result is
exp(-y^2/(2*tau)) - exp(-tau/2)
is the result convincing?

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

추가 답변 (0개)

카테고리

태그

질문:

2018년 3월 16일

댓글:

2018년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by