regular function integration failure

1 view (last 30 days)
fima v
fima v on 7 May 2020
Edited: fima v on 9 May 2020
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.
%Default Dataset_new file
data = load('Default Dataset4.csv');
x = data(:,1);
y = data(:,2);
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))
lambda = linspace(3.5e-6,23e-6,100000);
plot(lambda, multiplication_formula(lambda));
hold on
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;

Accepted Answer

Ameer Hamza
Ameer Hamza on 7 May 2020
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');

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by