regular function integration failure

2 vues (au cours des 30 derniers jours)
fima v
fima v le 7 Mai 2020
Modifié(e) : fima v le 9 Mai 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.
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;

Réponse acceptée

Ameer Hamza
Ameer Hamza le 7 Mai 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');
  2 commentaires
fima v
fima v le 7 Mai 2020
Thank you very much
Ameer Hamza
Ameer Hamza le 7 Mai 2020
I am glad to be of help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by