function [M,V,G,F] = fcn(q3,q4,qd1, qd2, qd3, qd4, qd5)
%#codegen
% Parameters considered in the manipulator.
l2 = 0.2; l3 = 0.2; l4 = 0.2;
lc2 = 0.0229; lc3 = 0.0229; lc4 = 0.02229;
m1 = 1.228; m2 = 1.023; m3 = 1.023; m4 = 1.023; m5 = 0.5114;
I2zz = 0.0058; I3zz = 0.0058; I4zz = 0.0058;
Fv1 = 0.03; Fv2 = 0.025; Fv3 = 0.025; Fv4 = 0.025; Fv5 = 0.02;
gz = 9.8;
% Inertia Matrix M
M11 = m1 + m2 + m3 + m4 + m5;
M12 = 0; M21 = 0; M13 = 0; M31 = 0; M41 = 0; M14 = 0; M25 = 0;
M35 = 0; M53 = 0; M52 = 0; M45 = 0; M54 = 0;
M15 = -m5;
M51 = -m5;
M22 = lc2^2*m2 + (l2^2 + lc3^2 + 2*l2*lc3*cos(q3))*m3 + ...
(l2^2 + l3^2 + lc4^2 + 2*l2*l3*cos(q3))*m4 + ...
2*(l3*lc4*cos(q4) + l2*lc4*cos(q3+q4))*m4 + ...
(l2^2 + l3^2 + l4^2 + 2*l2*l3*cos(q3))*m5 + ...
2*(l3*l4*cos(q4) + l2*l4*cos(q3+q4))*m5 + I2zz + I3zz + I4zz;
M23 = (lc3^2 + l2*lc3*cos(q3))*m3 + ...
(l3^2 + lc4^2 + l2*l3*cos(q3) + 2*l3*lc4*cos(q4))*m4 + ...
(l2*lc4*cos(q3+q4))*m4 + ...
(l2*l4*cos(q3+q4))*m5 + ...
(l3^2 + l4^2 + l2*l3*cos(q3) + 2*l3*l4*cos(q4))*m5 + I3zz + I4zz;
M32 = M23; % Symmetric property
M24 = (lc4^2 + l3*lc4*cos(q4) + l2*lc4*cos(q3+q4))*m4 + ...
(l4^2 + l3*l4*cos(q4) + l2*l4*cos(q3+q4))*m5 + I4zz;
M42 = M24; % Symmetric property
M33 = lc3^2*m3 + (l3^2 + lc4^2 + 2*l3*lc4*cos(q4))*m4 + ...
(l3^2 + lc4^2 + 2*l2*l4*cos(q4))*m5 + I3zz + I4zz;
M34 = (lc4^2 + l3*lc4*cos(q4))*m4 + (l4^2 + l3*l4*cos(q4))*m5 + I4zz;
M43 = M34; % Symmetric property
M44 = lc4^2*m4 + l4^2*m5 + I4zz;
M55 = m5;
M = [M11 M12 M13 M14 M15; M21 M22 M23 M24 M25; ...
M31 M32 M33 M34 M35; M41 M42 M43 M44 M45; ...
M51 M52 M53 M54 M55];
% Coriolis and Centrifugal Matrix V
Vm11 = 0; Vm12 = 0; Vm13 = 0; Vm14 = 0; Vm15 = 0; Vm21 = 0; Vm25 = 0;
Vm31 = 0; Vm35 = 0; Vm41 = 0; Vm44 = 0; Vm45 = 0; Vm51 = 0; Vm52 = 0;
Vm53 = 0; Vm54 = 0; Vm55 = 0;
Vm22 = -(lc3*m3 + l3*m4 + l3*m5)*l2*sin(q3)*qd3 + ...
(l2*sin(q3+q4)*qd3 - (l3*sin(q4) + l2*sin(q3+q4)*qd4)*(lc4*m4 + l4*m5));
Vm23 = -(lc3*m3 + l3*m4 + l3*m5)*l2*sin(q3)*qd2 - ...
(lc4*m4 + l4*m5)*l2*sin(q3+q4)*qd2 - ...
((lc3*m3 + l3*m4 + l3*m5)*l2*sin(q3)*qd3) - ...
(lc4*m4 + l4*m5)*l2*sin(q3+q4)*qd3 - ...
((lc4*m4 + l4*m5)*(l3*sin(q4) + l2*sin(q3+q4))*qd4);
Vm24 = -(lc4*m4 + l4*m5)*(l3*sin(q4) + l2*sin(q3+q4)*(qd2 + qd3 + qd4));
Vm32 = (lc3*m3 + l3*m4 + l3*m5)*l2*sin(q3)*qd2 + ...
(lc4*m4 + l4*m5)*l2*sin(q3+q4)*qd2 - ...
(lc4*m4 + l4*m5)*l3*sin(q4)*qd4;
Vm33 = -(lc4*m4 + l4*m5)*l3*sin(q4)*qd4;
Vm34 = -(lc4*m4 + l4*m5)*l3*sin(q4)*(qd2 + qd3 + qd4);
Vm42 = (lc4*m4 + l4*m5)*(l2*sin(q3+q4) + l3*sin(q4))*qd2 + ...
(lc4*m4 + l4*m5)*l3*sin(q4)*qd3;
Vm43 = (lc4*m4 + l4*m5)*l3*sin(q4)*(qd2 + qd3);
V = [Vm11 Vm12 Vm13 Vm14 Vm15; Vm21 Vm22 Vm23 Vm24 Vm25; ...
Vm31 Vm32 Vm33 Vm34 Vm35; Vm41 Vm42 Vm43 Vm44 Vm45; ...
Vm51 Vm52 Vm53 Vm54 Vm55];
% Friction Vector F and Gravity Vector G
F = [Fv1*qd1 Fv2*qd2 Fv3*qd3 Fv4*qd4 Fv5*qd5];
G = [(m1 + m2 + m3 + m4 + m5)*gz ; 0 ; 0; 0; -m5 * gz].';
end
error in this code