How to calculate the integral of a function with a spline in it

조회 수: 31 (최근 30일)
Renan Kops
Renan Kops 2017년 4월 21일
댓글: Andrew Newell 2017년 4월 25일
Hello Everybody,
So i have a function called FB, and it is the product of a couple of functions
nB = spline(Wavelength,B3);
emi = @(x) 1.989e-6*(10^9*x).^2-0.002;
FB = @(x,T) nB(x).*emi(x)./(x.^5.*(exp((h.*c)./(x.*k.*T))-1))
%integration:
RaBG(Counts) = integral(@(x)FB(x,T),400e-9,720e-9)
nB is a function i must adquire from data. When fitting it with a polinomial function i get a small error which i believe is making me get wrong results, though the code works. I'm trying to fit it with a spline but haven't been able to get the code to work. I also tryied calling FB as this, which didn't work:
FB = @(x,T) ppval(nB,x).*emi(x)./(x.^5.*(exp((h.*c)./(x.*k.*T))-1));
Can anyone please help me?
  댓글 수: 3
Renan Kops
Renan Kops 2017년 4월 24일
Some of my data is evenly spaced so I can use this, good idea!
Any alternatives for the data that isn't evenly spaced?
John D'Errico
John D'Errico 2017년 4월 25일
I'd like to chime in here,but without knowing what wavelength, B3, and G3 are, it is impossible to give a useful answer.

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

답변 (1개)

Andrew Newell
Andrew Newell 2017년 4월 24일
편집: Andrew Newell 2017년 4월 24일
For evenly or unevenly spaced data, you could use the trapezoidal rule (MATLAB function trapz).
Interpolation is also reasonable. How exactly isn't the code working?
I don't see any values assigned to c, k or T. Are you doing that earlier? If so, it would make sense to define
FB = @(x) ppval(nB,x).*emi(x)./(x.^5.* (exp((h.*c)./(x.*k.*T))-1));
  댓글 수: 7
Renan Kops
Renan Kops 2017년 4월 25일
Well it is possible, i will try to rescale it.
But, if that was the case, shouldn't i get wrong answers when integrating a 10th degree polinomial or with the Newton-Cotes method? Because both these methods worked and gave me a nice approximation of the real answer (For now i am trying to replicate the results of a paper to check if my code is performing as expected).
Thank you for all the help Andrew.
Andrew Newell
Andrew Newell 2017년 4월 25일
I'm glad to know that the alternative methods are working!

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

카테고리

Help CenterFile Exchange에서 Splines에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by