I want to integrate a function and program is given below:
close all;
clear all;
fun = @(x,y)x+(x./(y.^2));
fun1= @(y) y+ integral(@(x)fun(x,y), 0,1);
c1= integral(fun1,0,1)
In the above program if we are using 'y' instead of 'y.^2', then there is no error. But if we are using 'y.^2' error occurred matrix dimension must agree. But here we are using x, y as variable hence there should be no question of matrix dimension. If, anybody can solve the problem please help me . Any suggestions regarding this will be appreciated.

 채택된 답변

Torsten
Torsten 2017년 11월 22일

0 개 추천

fun1= @(y) y+ integral(@(x)fun(x,y), 0,1,'ArrayValued',true);
Note that fun is undefined at y=0. Thus c1 should come out as Inf.
Best wishes
Torsten.

댓글 수: 3

Thank you sir.. Actually, the question asked above is the proto-type of my problem. The actual problem is shown below.
clc;
clear all;
close all;
R=.01:.25:1; %bits /hz/sec
Pm= 10; Ps=2;t=1; q=4;
M=50; S=20; k = 15; al =0.3;
mu = 1; sigma= 2;
%mean of lognormaldistribution
Es= exp((2*mu/q) + 0.5* (2*sigma/q));
lambdas1 = 10;
lambdam1 = lambdas1/4;
lambdas= Es * lambdas1;
lambdam = Es* lambdam1;
u= (lambdam +(lambdas*(Ps/Pm)^(2/q)));
for n= 1: length(R)
ga1= (S/(M-S-1)).*((2.^(R(n)./al))-1);
fun = @(w,x) imag(exp(-2.*pi.*lambdas.*((1i.*w.*Ps).^(2/q)).*gamma(2-2/q).*gamma(2/q)./(q-2)).*exp(-1i.*w.*Pm./(ga1.*x.^q)).*exp(-pi.*lambdam.*(((gamma(1-2/q)+(2/q).*igamma(-(2/q),(-1i.*w.*Pm./x.^q)))./(-1i.*w.*Pm).^(-2/q))-x.^2)))./w;
c = @(x) integral(@(w) fun(w,x), 0,Inf,'ArrayValued',true)
fun1= @(x)((1/2)-((1/pi).*c(x))).*2.*pi.*lambdam.*x.* exp(-pi.*u.*x.^2);
c1 = integral(fun1, 0,Inf)
end
In that if i am using 'ArrayValued',true' there the program went to infinite loop and on stopping the program there is error message. Sir, please help me regard this.
Torsten
Torsten 2017년 11월 24일
I guess that the division by x^q for x=0 in "fun" is the problem.
Best wishes
Torsten.
Shweta Rajoria
Shweta Rajoria 2017년 11월 24일
Thank you sir.. my problem is solved with your suggestion.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

질문:

2017년 11월 22일

댓글:

2017년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by