Not enough input arguments. Help?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Not enough input arguments. Error in constraint (line 11) k1 = E*x(1)/l(1)*[(cos(a(1)))^2,sin(a(1))*cos(a(1));sin(a(1))*cos(a(1)),(sin(a(1))^2)];
This is my code:
function [c,ceq] = constraint(x)
% constraint: axial stress<=400N/m2
% x is the area of bar, x1=A1,x2=A2,x3=A3
% Load, geometry and materal
F = [10000e3;-2000e3];%unit change (kN--N)
E = 70E9;%Pa = N/m2
l = [2 2/sqrt(3) sqrt(2)];%m
a = [deg2rad(-30) deg2rad(-60) deg2rad(-135)];%rad
%bar 1 global matrix at node 4
k1 = E*x(1)/l(1)*[(cos(a(1)))^2,sin(a(1))*cos(a(1));sin(a(1))*cos(a(1)),(sin(a(1))^2)];
%bar 2 global matrix at node 4
k2 = E*x(2)/l(2)*[(cos(a(2)))^2,sin(a(2))*cos(a(2));sin(a(2))*cos(a(2)),(sin(a(2))^2)];
%bar 3 global matrix at node 4
k3 = E*x(3)/l(3)*[(cos(a(3)))^2,sin(a(3))*cos(a(3));sin(a(3))*cos(a(3)),(sin(a(3))^2)];
% nodal displacement in node 4
k = k1+k2+k3;
d4 = inv(k)*F; %P
%force component at each bar
f1 = k1*d4;
f2 = k2*d4;
f3 = k3*d4;
%axial force
s1 = (sqrt(f1(1)^2+f1(2)^2))/x(1);
s2 = (sqrt(f2(1)^2+f2(2)^2))/x(2);
S3 = (sqrt(f3(1)^2+f3(2)^2))/x(3);
%inequlity constraint
Fo = [s1 s2 S3]; %N/mm2
c = Fo-400;
%Equality constraint
ceq = []; %no equality constraint
end
3 comentarios
Ankit
el 1 de Abr. de 2020
it is working fine. how you are passing x (areas) to your function?
[c,ceq] = constraint([2 3 4])
Output in Matlab:
c =
1.6326e+06 1.8391e+06 1.5596e+06
ceq =
[]
Respuestas (1)
Constantino Carlos Reyes-Aldasoro
el 1 de Abr. de 2020
Your problem may be that you are calling your function without the required input parameters your function requires one parameter
function [c,ceq] = constraint(x)
so if you call your function without input parameters it will create an error. I created a simplified version of a function:
function [c,ceq] = constraint(x); c=x;ceq=x;end
and then call it with/without parameters, look:
>> [c,ceq] = constraint(2);
>> [c,ceq] = constraint();
Not enough input arguments.
Error in constraint (line 1)
function [c,ceq] = constraint(x); c=x;ceq=x;end
>>
Hope this helps. If this does not solve your question, let me know. If it does, please accept the answer.
2 comentarios
Constantino Carlos Reyes-Aldasoro
el 1 de Abr. de 2020
The code (your function) is fine, the problem is when you call the function. Somewhere, outside the function you must be calling the function, and you have not placed the value of x in that call.
Correct
% here you do something
% then you define x
x = 2;
% then you call your function
[c,ceq] = constraint(x);
% no errors coming from there
I have assumed the value of x=2 but it will be different in your setting.
Incorrect
% error will happen because you are not passing an input parameter
[c,ceq] = constraint();
Ver también
Categorías
Más información sobre Linear Least Squares en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!