Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
what do you expect to get? Matlab just showed you what you did. Do you understand the @(x,y) notation? –  natan Jun 8 '13 at 0:44
    
I don't understand any difference b/w two codes.Sorry I am not a pro in matlab.So if you can tell me what's wrong then your help will be appreciated. Thanks –  Avi Shri Jun 8 '13 at 1:47
1  
    
sorry but you are not helping.I have already read it and i still don't understand the difference b/w the two codes i wrote above. –  Avi Shri Jun 9 '13 at 0:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.