How can I create a ''fun=@x...'' function for integration by multipling ''fun= @x...'' functions that consists of the originals funs subarguments?
    25 views (last 30 days)
  
       Show older comments
    
    Konstantinos Dragonas
 on 1 Jul 2015
  
    
    
    
    
    Answered: chaman lal dewangan
      
 on 12 Mar 2018
            I would like to illustrate the following code but an error occurs: this code works: fun=@(x)(exp(-hlpexpvar.*x)).*(1-(x./univar(1)))
but how can I do something like this:
funone=@x exp(-hlpexpvar.*x)
funtwo=@x 1-(x./univar(1))
fun= @x funone.*funtwo
I would like to thank you in advance for any kind of help to this problem.
0 Comments
Accepted Answer
  Steven Lord
    
      
 on 1 Jul 2015
        You were close. I'm going to define values for the variables for demonstration purposes
 hlpexpvar = 1;
 univar = 2;
Now to define the three functions
 funone =@(x) exp(-hlpexpvar.*x);
 funtwo =@(x) 1-(x./univar(1));
You can't multiply function handles. However you can multiply the values returned by evaluating the function handles.
 fun = @(x) funone(x).*funtwo(x);
Let's check by comparing the integral of fun (using funone and funtwo) and the explicitly specified function fun2.
 fun2 = @(x) exp(-hlpexpvar.*x).*(1-(x./univar(1)));
 answer1 = integral(fun, 0, 1)
 answer2 = integral(fun2, 0, 1)
More Answers (1)
See Also
Categories
				Find more on Encryption / Cryptography in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

