Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Help regarding usage of Anonymous functions
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I am newbie to matlab and require some help in the usuage of Anonymous functions for the following scenario. I would like to implement the below equation using anonymous function.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156075/image.png)
The above probability should be function of Deltax
the conditional probability is given by
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156077/image.png)
m and n are constants
and the probability of A is given by
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156079/image.png)
In all the above equations, execpt Delatax every other is constants.
Could someone give some suggestions how to approach this scenario using anonymous functions
댓글 수: 2
Star Strider
2016년 2월 27일
For starters, define ‘conditional probability’ and ‘A’ in this context.
The three expressions all simply appear to be floating in space with no obvious relationship to each other.
답변 (2개)
Konstantinos Sofos
2016년 2월 27일
편집: Konstantinos Sofos
2016년 2월 27일
Hi,
Firstly i fully agree with the comment of Star Strider. Because as you say you are "newbie" to matlab i would suggest you to read what is an Anonymous Function. If you read this, then it will be very easy to understand that you could write simple e.g your second ?equation? as
my_eq = @(dx)(.5*(erf(m*dx/2*sigma_n)-erf(n*dx/2*sigma_n));
% And run a test case
a = my_eq(0.5)
After this i hope you become expert ;)
댓글 수: 1
Star Strider
2016년 2월 28일
This is how I would do it:
P_qi_a = @(l,i,dx,sh) (erf((l(1) + i.*dx)./(sqrt(2)*sh)) - erf((l + (i+1).*dx)./(sqrt(2)*sh)))/2;
P_qj_qi = @(m,n,dx,sn) (erf(m.*dx./(2*sn)) - erf(n.*dx./(2*sn)))/2;
dx = ...; % Define Constants
sh = ...;
m = ...;
n = ...;
sn = ...;
N = ...;
i = 1:N; % Define Vector
l = ...; % Define Vector
P_qj = @(dx) sum( P_qj_qi(m,n,dx,sn) .* P_qi_a(l,i,dx,sh) );
[P_qj_1, fval] = fzero(@(dx) P_qj(dx)-1, 0.5); % Solve For ‘P_qj = 1’
This is based on what you’ve posted thus far, so if there are any errors in them, you will need to correct them. If ‘l’ is a function of ‘i’, you will need to create a vector for it that is equal in length to ‘i’
NOTE — This is obviously UNTESTED CODE so I cannot guarantee that it will produce the results you want, or for that matter, that it runs correctly. That’s the problem with hypothetical problems such as this.
I have no idea what you’re doing, so you’re on your own from here.
댓글 수: 2
Star Strider
2016년 2월 28일
My pleasure.
I cannot follow what you are doing. All I did was create anonymous functions for your equations, as you requested, just as you posted them. You want to find the value of ‘dx’ (delta x) where the summation equals 1, and the fzero call does that (providing that zero-crossing exists, since the function itself appears continuous and continuously differentiable). All my equations are vectorised, so they should be robust. I will leave you to apply them to your data. You are free to change them and adapt them as you wish.
If you have vectors or matrices you need to multiply or do other operations on, see the documentation on Array vs. Matrix Operations. Another useful function for what you want to do is bsxfun. Experiment with bsxfun on sample data that do not involve the anonymous functions I wrote for you so you can learn how it works. If you are doing fundamental matrix and array operations and calculations, see the documentation covering those areas.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!