Index exceeds the number of array elements error when using fsolve
Show older comments
I'm working on a project in which one part solves for the position solutions from a vector loop equation I generated. The code reads as follows:
%%position solution
%VLE: -R1 - R2 + R3 = 0
%defining fixed/knowns (m) - using average values of males (Table 2)
R1 = 0.4; %length of thigh
R2 = 0.4; %length of shin
th3 = 90*(pi/180); %converted to radians
%using fsolve for position solution *requires installation of optimization toolbox in MatLab
PAs = zeros(141,3); %empty array for th1 and R3, respectively, (unknowns) to be placed
for ii = 0:140 %to iteart through all possible input angles (degrees)
theta2 = ii*(pi/180); %converst to radians
PAs(ii+1,1) = theta2; %fills first spot in array with input value (th2) - knee angle of flexion
F1 = @(x) [-R1*cos(x(2)*(pi/180))-R2*cos(theta2); -R1*sin(x(2)*(pi/180))-R2*sin(theta2)+x(3)];
PAs(ii+1, [2 3]) = fsolve(F1, [0, 0.8]); %initial values (taken from standing leg)
end
th2 = PAs(:,1);
th1 = PAs(:,2);
r3 = PAs(:,3);
However, when I run it, I get an error reading "index exceeds number of array elements" and thus fsolve will not compute. Is anyone able to see any issues with my code that would cause this error?
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!