Hi, I am trying to solve an integration where both limits are variable. The function itself being integrated is simple, it is just exp(-W^2). I can solve the inegration fine using this method without limits - the limits are the issue here. I think it could be because of the use of the symbolic functions to integrate? But I have tried other methods, and I cannot get it to work with these limits. I get the error:
error in sym/subsref (line 898)
R_tilde = builtin('subsref',L_tilde,Idx);
The upper limit is -phi, and the lower limit is beta-phi.
Another issue could be because the upper limit is the same as the variable being integrated. However I don't know how to get around that issue either?
I have just shown some of my code, hopefully this is enough to make sense of what I am trying to do. Any help would be greatly appreciated!
t=linspace(0,1000);
r=linspace(0,100);
D=2;
beta=r./sqrt(4*D.*t);
phi=U.*sqrt(t./D);
W=beta-phi;
% Performing integration
syms W
f=exp(-(W.^2));
a=-phi;
b=beta-phi;
int(f,W,a,b)

댓글 수: 3

Bjorn Gustavsson
Bjorn Gustavsson 2020년 9월 19일
Use the error-function, erf, and then you're done - if this is your full problem...
Sophie Malcolm
Sophie Malcolm 2020년 9월 20일
Hi Bjorn,
Thank you so much for your response, I hadn't considered the use of the error function in MATLAB and will look into that now!
Thanks so much,
Sophie
Your solution is simply:
(pi^(1/2)*(erf(b) - erf(a)))/2.

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

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 19일

0 개 추천

You are getting an error because you are passing arrays (a and b) to int() as its limit. The limits must be scalar. For example, try this
t=linspace(0,1000);
r=linspace(0,100);
D=2;
U = 3;
beta=r./sqrt(4*D.*t);
phi=U.*sqrt(t./D);
W=beta-phi;
% Performing integration
syms W
f=exp(-(W.^2));
a=-phi;
b=beta-phi;
int(f,W,a(2),b(2))

댓글 수: 2

Sophie Malcolm
Sophie Malcolm 2020년 9월 20일
Hi Ameer,
Thank you so much for this, I didn't realise that! That is so helpful, thanks a lot.
Sophie
Ameer Hamza
Ameer Hamza 2020년 9월 20일
I am glad to be of help!

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

추가 답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2020년 9월 19일

0 개 추천

Matlab has both a numerical and a symbolic version of the error-function. That will be the answer to your problem. The numeric version is vectorized, so it can handle your inputs without problems.
HTH

댓글 수: 1

Sophie Malcolm
Sophie Malcolm 2020년 9월 20일
Hi,
Okay that makes a lot of sense! Thank you so much for explaining. I will look into that now.
Thanks for your help,
Sophie

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

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 9월 19일

댓글:

2020년 9월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by