필터 지우기
필터 지우기

How can I create a ''fun=@x...'' function for integration by multipling ''fun= @x...'' functions that consists of the originals funs subarguments?

조회 수: 40 (최근 30일)
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.

채택된 답변

Steven Lord
Steven Lord 2015년 7월 1일
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)
  댓글 수: 1
Konstantinos Dragonas
Konstantinos Dragonas 2015년 7월 1일
Thank you very much for your help! This is the only problem i had in my effort to make a dynamic program that will take as input a rate transition matrix and and calculate the steady state probabilities by semi markov model.

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

추가 답변 (1개)

chaman lal dewangan
chaman lal dewangan 2018년 3월 12일
Thanks, I understood how to use "fun".

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by