Find integral of a function where upper limit changes inside the function
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I want to calculate integral of in equation 12 in image.

When t=30,D=250, x=40., I have found it with following code
t = 30
a=@(g) ((t-g).^(-1.5)).*exp(-4./(t-g));
b=integral(a,0,t);
h=282.09.*b
But I am unable to do it when t is a vector say t = 1:30, it means I want to find out h at every t from 1 to 30.
채택된 답변
for t = 1:1:30
a=@(g) ((t-g).^(-1.5)).*exp(-4./(t-g));
b=integral(a,0,t);
h(t)=282.09.*b
end
댓글 수: 12
You would need
h(t)=282.09.*b
to return all of the values.
Exactly, I forgot to mention it.
@cvklpstunc thank you for answer. As I also want to change g for every step. I have written following code for that..
p = 30; % number of steps
t = 1:30;
gt = sin(linspace(0,20,p));
D = 100; x = 40;
out_of_integral = sqrt(1/D)*x / (2*sqrt(pi));
fun = @(tau,gt,t) gt*(t-tau).^(-1.5).*exp(-x^2./(4*D*(t-tau)));
h = zeros(1,p);
for i = 1:p
q = integral(@(tau)fun(tau,gt(i),t(i)),0,t(i));
h(i) = q*out_of_integral;
end
Can you please see if it is correct? I have no means to validate my code when both g and t change for every timestep.
There seems nothing wrong with indexing or anything else.
Atr cheema
2017년 11월 7일
편집: Atr cheema
2017년 11월 7일
@cvklpstunc The red line in image shows the result from this code. It shows temperture at x=30, with time.

What I am unable to understand is, why output amplitude keeps on increasing while the input amplidue is constant. I expect output amplitude to be more or less constant as seen from the result of finite difference code here (yellow line).
The red line shows the result from above code.
In your integral, for given time t(i), gt is constant over [0,t(i)], namely gt(i). That's wrong because gt varies with tau.
Best wishes
Torsten.
@Torsten Can you please make the correction i.e how can I make g as a function of tau?
D = 100;
x = 40;
t = 1:30;
g = @(tau) sin(tau);
fun = @(tau,t) g(tau).*(t-tau).^(-1.5).*exp(-x^2./(4*D*(t-tau)));
for i=1:numel(t)
tscal=t(i);
q(i) = integral(@(tau)fun(tau,tscal),0,tscal);
end
q = sqrt(1/D)*x/(2*sqrt(pi))*q;
plot(t,q)
Best wishes
Torsten.
@Torsten I fear the solution is stil not correct. Have you looked at the output from your code, it looks like this

This is the solution of 1D heat equation and the result should similar to as yellow line I pasted above. If the input is sine wave at x=0, then I should have a sine wave with constant but lower amplitude at x=40 and a shifted phase as compared to sine wave at x=0.
I don't see anything wrong in the code.
Maybe you could try plotting q on a finer and longer t-grid (till t=60, e.g.) and strengthen the tolerances RelTol and AbsTol for the integrator.
I get a reasonable result this way.
Best wishes
Torsten.
Atr cheema
2017년 11월 7일
편집: Atr cheema
2017년 11월 7일
@Torsten may be I am getting nothing at all. How can I come from the graph from your code to the target graph which I mentioned before where I have input sine wave g(t) (black line) and output (yellow line)?
Change
x = 40;
t = 1:30;
g = @(tau) sin(tau);
to
x = 30;
t = linspace(0.05,100,2000);
g = @(tau) sin(tau/2);
in the above code.
Best wishes
Torsten.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
