Sum of Function Handles
Show older comments
I'm fairly new to Matlab and I have read several posts about summing function handles, but I can't quite figure out how to apply it to my problem so I was hoping someone could help me. I'm attempting to optimize strain of a net placed over a mesh.
I have a cell of function handles. They provide a parametrization of points placed on a mesh. For example:
v{1} = @(s) (P(1:3,1)-P(1:3,2))*s+P(1:3,2)
where the P correspond to vertices on the original mesh.
I created a function which calculates the square of the strain for each strand (strandstrain in the program below).
I'd now like to create a sum of the strains for all the strands; however, I can't for the life of me figure out how to do this without utilizing symbolic functions. I've already done symbolic; however, it was quite slow so I am trying to avoid it if possible.
I thought about putting the strains into another cell or array function and then summing them, but since I need variable dependence shared between different elements I'm not quite sure how to do this. For instance the strain between two neighboring strands will need the placement of the shared vertex (recall parametrized) to have a shared variable. I have the program below. I'm looking to minimize the total strain with fmincon. Any help is greatly appreciated.
vert = cell(8);
%This takes care of the vertical points.
for i = [1]
for j = [0:6]
vert{(i-1)*6+j+1} = @(t) vertex0(1:3,9*(j)+i);
end
end
%These are the bottom half of the vertical strands
for i = [2:8]
for j = [0:3]
vert{8+7*(i-2)+j} =@(t) (vertex0(1:3,9*(j+1)+i) - vertex0(1:3,9*j+i))*t+vertex0(1:3,9*j+i);
end
end
%These are the top half of the vertical strands
for i = [2:8]
for j = [4:6]
vert{12+7*(i-2)+(j-4)} =@(t) (vertex0(1:3,9*(j)+i) - vertex0(1:3,9*(j-1)+i))*t+vertex0(1:3,9*(j-1)+i);
end
end
%This is for the right vertical strands which are fixed.
for i = [9]
for j = [0:6]
vert{57+j} =@(t) vertex0(1:3,9*(j)+i);
end
end
%This takes care of the points on the diagonals.
diag = cell(7);
for i = [1:4]
for j = [0:5]
diag{(i-1)*6+j+1}=@(t) (vertex0(1:3,10+j*9+i)-vertex0(1:3,i+j*9))*t+vertex0(1:3,i+j*9);
end
end
for i = [5:8]
for j = [0:5]
diag{(i-1)*6+j+1}=@(t) (vertex0(1:3,9+j*9+i)-vertex0(1:3,1+i+j*9))*t+vertex0(1:3,1+i+j*9);
end
end
%This calculates strain along each strand. In the deformed case a strand is
%comprised of three points p1,p2,p3 and in the reference config we have two
%points u1,u2
strandstrain = @(p1,p2,p3,u1,u2) ((norm(p1-p2)+norm(p2-p3)-norm(u1-u2))/norm(u1-u2))^2
Answers (0)
Categories
Find more on Parallel Computing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!