English 中文(简体)
在Matlab发挥整体作用的职能
原标题:Function for taking a integral in Matlab
  • 时间:2012-05-11 10:16:25
  •  标签:
  • matlab

I made a function to take intergal Likehood(L,U,gamma,sigma), but there are some error. Here is my Matlab code.

function func=Likelihook(L,U,gamma,sigma)
Lstar=3;
Ustar=20;
gammastar=1.5;
a=0.2;
func=-0.5.*log(2.*pi)-log(sigma)+log(gamma)-log(L.^(-gamma)-U.^(-gamma))+quad(@(y)(log(quad(@(x)(x.^(-gamma-1).*exp(-0.5.*((y-x)./sigma).^2)),L,U)).*gammastar./(sqrt(2*pi).*Lstar.^(-gammastar)-Ustar.^(-gammastar)).*quad(@(x)(x.^(-gammastar-1)./(a.*x).*exp(-0.5.*((y-x)./(a.*x)).^2)),Lstar,Ustar)),-inf,inf) ;

这里是需要计算的职能。

https://i.stack.imgur.com/lP1lz.png

没有人帮助我?

最佳回答

Explanation

Matlab tries to compute the integration vectorially, so

f = @(x) x;
quad(f(x) x,1,5)

接受评价的情况类似

sum(f(1:dx:5))

with matlab figuring out what the discretization interval should be. This is computable, because f = @(x) x takes vectorial input.

当你具有双重整体性时,你便会这样做:

f = @(x,y) x+y;
quad(quad(f(x,y) x,1,5),4:10)

......

sum(sum(f(1:dx:5,),4:dy:10))

仅对<代码>1:dx:5和4:dy:10进行评价。 情况相同(不太可能)。

Solution

当然,你可以通过调整你的职能来解决这一问题。 这样,它就把任何两种病媒作为投入,例如使用阵列。

对于你的问题,情况如下:

func = -0.5.*log(2.*pi)-log(sigma)+log(gamma)-log(L.^(-gamma)-U.^(-gamma)) ...
+quad(@(y)( ...
    log( arrayfun(@(z) quad(@(x)( x.^(-gamma-1).*exp(-0.5.*((z-x)./sigma).^2)),L,U), y) ) ...
    .* gammastar./(sqrt(2*pi).*Lstar.^(-gammastar)-Ustar.^(-gammastar)) ...
    .* arrayfun(@(z) quad(@(x)( x.^(-gammastar-1)./(a.*x).*exp(-0.5.*((z-    x)./(a.*x)).^2)),Lstar,Ustar), y) ...
),-inf,inf) ;

插入一些分界线(.),以便于阅读:

Remarks

由于将<条码>-Inf 至:Inf:载于 rel=“nofollow”>号文件,我不肯定这是否会给你带来坚实的结果。

如果间隔期为定点,[a,Inf],那么就存在(x)的成分而言,(x)必须折合为十条方法。

so, you ll have to make sure that this is the case, otherwise you ll keep getting NaNs

问题回答

暂无回答




相关问题
MATLAB Solving equations problem

I want to solve these equations using MATLAB and I am sure there is a non zero solution. The equations are: 0.7071*x + 0.7071*z = x -0.5*x + 0.7071*y + 0.5*z = y -0.5*x - 0.7071*y +...

Difference between MATLAB s matrix notations

How do you read the following MATLAB codes? #1 K>> [p,d]=eig(A) // Not sure about the syntax. p = 0.5257 -0.8507 -0.8507 -0.5257 d = ...

preventing data from being freed when vector goes out of scope

Is there a way to transfer ownership of the data contained in a std::vector (pointed to by, say T*data) into another construct, preventing having "data" become a dangling pointer after the vector goes ...

Divide two polynomials using MATLAB

I want to divide p(x) by q(x) given that: p(x)=-5x^4+3x^2-6x q(x)=x^2+1 I tried: p=inline( -5*(x^4)+3*(x^2) , x ) p = Inline function: p(x) = -5*(x^4)+3*(x^2) q=inline( x^2+1 , x ) q = ...

matlab deals with Fibbonacci

The Fibonacci series is given as follows: 1, 2, 3, 5, 8, 13, 21, ... How can I write a script which calculates and prints the n-th Fibonacci term (for n>2), where n is inputed by the user. This ...

How do I plot lines between all points in a vector?

I have a vector containing some points in 2-D space. I want MATLAB to plot these points with lines drawn from every point to every other point. Basically, I want a graph with all vertices connected. ...

How do I create a string using a loop variable in MATLAB?

I have a loop like this: for i=1:no %some calculations fid = fopen( c:\out.txt , wt ); %write something to the file fclose(fid); end I want data to be written to different files like ...