Info
This question is closed. Reopen it to edit or answer.
How to code this equation ?
2 views (last 30 days)
Show older comments
Hello,
I've a problem and I hope that someone have an idea to help me.
I have to code this equation in Matlab :
I try this way to code it :
for i = 1 : N
ci = @(sigma_1,sigma_2,x_1,y_1,x_2,y_2,R,c) 1/(sigma_1)*exp(-((x_1.^2+y_1.^2)/(sigma_1)))*K_12(x_1,y_1,x_2,y_2,R,c(i,:));
ci_2 = @(sigma_1,sigma_2,x_1,y_1,R,c) (1-integral2(@(x_2,y_2) ci(sigma_1,sigma_2,x_1,y_1,R,c(i)),0,10,0,10));
ci_2_vect(1,i) = @(sigma_1,sigma_2,x_1,y_1,R,c) arrayfun(@(x,y) ci_2(sigma_1,x,y,R,c(i,:)),x_1,y_1);
end
P = @(sigma_1,sigma_2,R,c) 1/(sigma_1)*integral2(@(x_1,y_1) exp(-((x_1.^2+y_1.^2)/(sigma_1)))*(1-prod(ci_2_vect(x_1,y_1,R,c))),0,10,0,10);
P(sigma_1,sigma_2,R,c(:,:,1))
Of course it doesn't work with this error :
"Error using arrayfun All of the input arguments must be of the same size and shape. Previous inputs had size 1 in dimension 1. Input #3 has size 100."
K is binary function so it's easy but I think I have a problem when I try to store my N functions to integrate in ci_2_vect. I have a product from 1 to N and so I have N different functions (as you can see, c is a matrix 2xN so for each subscript i my function is changing).
Think you very much if someone have an idea.
Brice
1 Comment
Walter Roberson
on 22 Aug 2015
The notation is not clear.
The only reference to "i" is in the form c(i). K12 takes "c" as its final parameter and references "c(i)" without indication of whether c is a function or an array being indexed or if it designates a point pair. Meanwhile, the one place that invokes K12 does so passing c(i) in to the final parameter. So whatever c(i) evaluates to is being passed as the final parameter to K12, which then applies the "(i)" to it again.
The |c(i) - (x1,y1) - (x2,y2)||| might be a magnitude calculation on c(i) - (x1,y1) - (x2,y2) . Working out what it is to mean is going to depend crucially on what c(i) designates. It kind of looks like the whole is intended to be testing whether two points are both within a particular radius of a center point, but the math does not look right for that.
Answers (1)
Gareth Thomas
on 22 Aug 2015
if you use Mupad (from the Symbolic Toolbox) you can always generate MATLAB functions automatically see here:
I think that it will be easier for you to type the equation in Mupad.
At the command line just type: mupad
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!