I am doing a molecular dynamics Finite Element Simulation for crack/impurities in materials. I tried this simpler code which works on command window :
k = [1,2,3,4,5];
c = [1,2,3,4,5];
F{2} = @(x,y) (x*y*0);
F{k(2)} = @(x,y) ((x>c(1))*(x<c(3))*(x^2) + F{k(2)}(x,y));
It works and gives correct output when i evaluate :
F{2}(2,2)
ans =
4
but when i try this in a loop with same syntax it does not evaluate the value of the function :
for i = 1:(n+1)^2
SF{i} = @(x,y) 0*(x+y);
end
for i = 1:n^2
x1 = x_coord(elements(i,1));
x2 = x_coord(elements(i,2));
x3 = x_coord(elements(i,3));
x4 = x_coord(elements(i,4));
y1 = y_coord(elements(i,1));
y2 = y_coord(elements(i,2));
y3 = y_coord(elements(i,3));
y4 = y_coord(elements(i,4));
range = (x>=x1)*(x<=x3)*(y>=y1)*(y<=y3);
SF{elements(i,1)} = @(x,y)((range*((x-x3)*(y-y3))/((x1-x3)*(y1-y3))) + SF{elements(i,1)}(x,y));
SF{elements(i,2)} = @(x,y)((range*((x-x4)*(y-y4))/((x2-x4)*(y2-y4))) + SF{elements(i,2)}(x,y));
SF{elements(i,3)} = @(x,y)((range*((x-x1)*(y-y1))/((x3-x1)*(y3-y1))) + SF{elements(i,3)}(x,y));
SF{elements(i,4)} = @(x,y)((range*((x-x2)*(y-y2))/((x4-x2)*(y4-y2))) + SF{elements(i,4)}(x,y));
Here 'elements' and 'x_coord' matrices are already defined before,then output comes something like this :
SF{1}(0,0)
ans =
piecewise([0 < x and 0 < y, (9*x*y)/4 + 1 < (81*x*y)/4 + 1])
I can not understand what is the problem here. Please Help.