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.
The above probability should be function of Deltax
the conditional probability is given by
m and n are constants
and the probability of A is given by
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!