MATLAB Answers

multiplication of functions integration problem

9 views (last 30 days)
fima v
fima v on 7 May 2020
Edited: fima v on 11 May 2020
Hello,i have two functions "fun" and "coef_fun"
"coef_fun" was created with interpolation of the attached CSV and it looks like in the photo bellow.
I have integrated fun over some interval ,and i got some numeric result.
When i tried to integrate the multiplication of fun and coeff_fun (in order to see the reduction the the numeric result)
It gives me an error "Undefined operator '*' for input arguments of type 'function_handle'"
i have attached my code.
Where did i go wrong in integrating multiplication of functions?
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);

  0 Comments

Sign in to comment.

Accepted Answer

ChrizzzlP
ChrizzzlP on 7 May 2020
mult_fun needs to be defined as a function too. simple example below:
fun = @(x)x+3;
coef_fun = @(x) 5*x+9;
multiplication_func = @(x) fun(x)*coef_fun(x);
multiplication_func(2)

  3 Comments

Steven Lord
Steven Lord on 7 May 2020
You can't multiply function handles.
multiplication_formula = @(lambda) fun*coef_fun;
You can multiply the values you receive when you evaluate function handles.
multiplication_formula = @(lambda) fun(lambda).*coef_fun(lambda);
I switch to using element-wise multiplication (the .* operator) instead of the matrix multiplication operator (the * operator) because I see you're passing this function handle multiplication_formula into integral. Generally you want to use the element-wise operators in functions you're going to pass into integral, ode45, and similar functions.
fima v
fima v on 7 May 2020
Hello Steven when i did the "fun" ONLY integration,fun_integral results in 43
But when i integrate the element wise multiplication you suggested( which is adding a filter and it should reduce the integral result)instead i get NAN in the mult_integral.
it said "Warning: Infinite or Not-a-Number value encountered"
Why my integral exploded?
What could be done?
Thanks
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);
fima v
fima v on 7 May 2020
Hello I was able to integrate the Purple plot over the range and it gave me 43
Why when i integrate the smaller green plot My integral explodes?
Thanks.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!