regular function integration failure

조회 수: 2 (최근 30일)
fima v
fima v 2020년 5월 7일
편집: fima v 2020년 5월 9일
Hello, i have two functions .The first called "fun" (purple in the plot) is integrated great and i get a precise result of 43 from my definite Matlab integral function.
shown in "fun_integral" expression.
The second one called "multiplication_formula" (BLUE in the plot) when goes into the same integration explodes and i get NAN in the "mult_integral expression.
Why is that? please help me understand where did i go wrong applying the integration of "multiplication_formula" .
I have the code bellow and csv file attached.
Thanks.
%Default Dataset_new file
data = load('Default Dataset4.csv');
x = data(:,1);
y = data(:,2);
%plot(x,y);
data_x1=x*0.000001; %transform to micron
[data_k, index] = unique(data_x1);
coef_fun = @(lambda) interp1(data_k, y(index), lambda); %%%%FIRST FUNCTION
%lambda = linspace(3.5e-6,23e-6,100000);
%plot(lambda, coef_fun(xq))
%title('interp1')
multiplication_formula=@(lambda)fun(lambda).*coef_fun(lambda);
lambda = linspace(3.5e-6,23e-6,100000);
plot(lambda, multiplication_formula(lambda));
hold on
plot(lambda,fun(lambda),'blue');
hold off
fun_integral= integral(fun,3.5e-6,23.5e-6)/10;
mult_integral= integral(multiplication_formula,3.5e-6,23.5e-6)/10;

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 7일
This happens when the value of lambda in integral goes beyond the values of 'data_k' used in interp1. By default, it gives NaN values in that case. You can specify it to extrapolate the values beyond the specified range.
coef_fun = @(lambda) interp1(data_k, y(index), lambda, 'linear', 'extrap');
  댓글 수: 2
fima v
fima v 2020년 5월 7일
Thank you very much
Ameer Hamza
Ameer Hamza 2020년 5월 7일
I am glad to be of help.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by