Borrar filtros
Borrar filtros

Not enough input arguments error. Help?

2 visualizaciones (últimos 30 días)
Charlotte Massie
Charlotte Massie el 1 de Abr. de 2020
Comentada: dpb el 1 de Abr. de 2020
function [c,ceq] = constraint(A)
% Define node coordinates (mm)
nod_coor = [(1000*sqrt(3)) 0;0 1000;((2000*sqrt(3))/3) 1000;(1000*(1+sqrt(3))) 1000];
ele_nod = [1 2;1 3;1 4];% Define Elements between nodes
num_ele = size(ele_nod,1);% Number of Elements
num_nod = size(nod_coor,1);% Number of nodes
ele_dof = [1 2 3 4;1 2 5 6;1 2 7 8];% Define element dof
% Define structural properties Area, MoE, Density
E(1) = 70e3; %N/mm^2 for Aluminium
E(2) = 70e3; %N/mm^2 for Aluminium
E(3) = 70e3; %N/mm^2 for Aluminium
% Initialise zero matrix for all matrices
displacement = zeros(2*num_nod,1);
force = zeros(2*num_nod,1);
stiffness = zeros(2*num_nod);
% Apply loads at DOF's (N)
force(1) = 6000.0e3;
force(2) = -10000.0e3;
% Boundary conditions
displacement(3,1) = 0.0;
displacement(4,1) = 0.0;
displacement(5,1) = 0.0;
displacement(6,1) = 0.0;
displacement(7,1) = 0.0;
displacement(8,1) = 0.0;
% Computation of the system stiffness matrix
for e = 1:num_ele
% Compute element length
L(e) = sqrt((nod_coor(ele_nod(e,2),1)-nod_coor(ele_nod(e,1),1))^2+...
(nod_coor(ele_nod(e,2),2)-nod_coor(ele_nod(e,1),2))^2);
% Compute the (theta) = (xj-xi)/L
cos = (nod_coor(ele_nod(e,2),1)-nod_coor(ele_nod(e,1),1))/L(e);
sin = (nod_coor(ele_nod(e,2),2)-nod_coor(ele_nod(e,1),2))/L(e);
% Compute element stiffness matricies
k = ((A(e)*E(e)/L(e))*[cos*cos cos*sin -cos*cos -cos*sin; cos*sin sin*sin -cos*sin -sin*sin;...
-cos*cos -cos*sin cos*cos cos*sin; -cos*sin -sin*sin cos*sin sin*sin]);
% Extract the rows of the ele_dof for each element e
% Compute global stiffness matrix
ele_dof_vec = ele_dof(e,:);
for i = 1:4
for j = 1:4
stiffness(ele_dof_vec(1,i), ele_dof_vec(1,j))=...
stiffness(ele_dof_vec(1,i), ele_dof_vec(1,j))...
+ k(i,j);
end
end
end
% known force array: input boundery conditions
known_f_a = [1;2];
for i = 1:size(known_f_a,1)
dis_new(i,1) = displacement(known_f_a(i,1),1);
force_new(i,1) = force(known_f_a(i,1),1);
end
for i = 1:size(known_f_a,1)
for j = 1:size(known_f_a,1)
stiff_new(i,j) = stiffness(known_f_a(i,1),known_f_a(j,1));
end
end
% Solving the partitoined matrix
dis_new = stiff_new\force_new;
for i=1:size(known_f_a,1)
displacement(known_f_a(i,1),1)=dis_new(i,1);
end
% Known displacement array
known_dis_a = [3;4;5;6;7;8];
for i = 1:size(known_dis_a,1)
force(known_dis_a(i,1),1) = stiffness(known_dis_a(i,1),:)...
*displacement;
end
% stress in elements
for e = 1:num_ele
L(e)=sqrt((nod_coor(ele_nod(e,2),1)-nod_coor(ele_nod(e,1),1))^2+...
(nod_coor(ele_nod(e,2),2)-nod_coor(ele_nod(e,1),2))^2);
cos=(nod_coor(ele_nod(e,2),1)-nod_coor(ele_nod(e,1),1))/L(e);
sin=(nod_coor(ele_nod(e,2),2)-nod_coor(ele_nod(e,1),2))/L(e);
stress(e)=(E(e)/L(e))*[-cos -sin cos sin]*displacement((ele_dof(e,:))');
end
disp('stiffness')
stiffness
disp('displacement')
displacement
disp('force')
force
disp('stress')
stress'
k=0;
for i = 1:num_nod
for j=1:2
k=k+1;
nod_coor_def(i,j)=nod_coor(i,j)+displacement(k,1);
end
end
% Determine force's in elements
for e = 1:num_ele
F(e) = sqrt(force(ele_dof(e,3))^2+force(ele_dof(e,4))^2)
end
% Inequlity constraint
X = [A(1) A(2) A(3)]
c = F-400*X %N/mm2
%Equality constraint
ceq = []; %no equality constraint
end
This is the error i am recieving. Thanks in advance.
Not enough input arguments.
Error in constraintdom (line 51)
k = ((A(e)*E(e)/L(e))*[cos*cos cos*sin -cos*cos -cos*sin; cos*sin sin*sin -cos*sin -sin*sin;...
  1 comentario
dpb
dpb el 1 de Abr. de 2020
Not obvious but aliasing cos() and sin() isn't a wise thing to do. It doesn't look like should cause a problem here, but there's so much code to look at could easily have missed something in visual inspection.
I'd start by making a local variable like cs, sn or something similar in place of cos, sin and then go from there.

Iniciar sesión para comentar.

Respuestas (1)

Ameer Hamza
Ameer Hamza el 1 de Abr. de 2020
Editada: Ameer Hamza el 1 de Abr. de 2020
sin and cos are name of MATLAB built-in functions. You have also created variable with this name. This can create confusion for MATLAB. Change your variable names to something else.

Categorías

Más información sobre Particle Swarm en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by