MATLAB Answers

0

Undefined function 'matlabFunction' for input arguments of type 'double'.

Asked by Akshay Pratap Singh on 31 May 2019
Latest activity Commented on by Star Strider
on 6 Jun 2019
I wrote a following code. If I remove H4_b, the code runs otherwise not. Rest all are ok.
dbstop if error
clear all
clc
format longEng
syms y1 y2 x y q
phi=(pi/180)*39;
delta=(2*phi)/3;
gma=18.4;
a=[2.5;0.532];
% kh=0.3;
Q=linspace(0,100,6);
h=4;
lam=0.2;
% q=50;
nq=2*q/(gma*(h+x));
A=lam*nq/(1+nq);
kh=0.3;
kv=kh;
psi=atan(kh/(1-kv));
beta=1.3;
alfa=1.3;
R1=-1;
R3=-(alfa*(y2))^0.5;
R2=3*(beta*(1-y1))^0.5;
R4=3*(alfa*(y2))^0.5;
delm1=0.5*(1-R1)*delta;
delm3=-0.5*(1-R3)*delta;
% delm2=0.5*(R2-1)*delta;
% delm4=0.5*(R4-1)*delta;
m=phi+delm1;
b=phi-psi;
c=psi+delm1;
alphac=atan((sin(m)*sin(b)+(sin(m)^2*sin(b)^2+sin(m)*cos(m)*sin(b)*cos(b)+A*cos(c)*cos(m)*sin(b))^0.5)/(A*cos(c)+sin(m)*cos(b)));
kg=(tan(alphac-phi)+(kh/(1-kv)))/(tan(alphac)*(cos(delm1)+sin(delm1)*tan(alphac-phi)));
r=1-lam*tan(alphac);
kq=r*kg;
pg=0.5*gma*(1-kv)*kg*(h+x)^2*cos(delm1);
pq=(1-kv)*q*kq*(h+x);
k3=(2*cos(phi-psi)^2)/(cos(phi-psi)^2*(1+R3)+cos(psi)*cos(delm3+psi)*(1-R3)*(1+sqrt((sin(phi+delm3)*sin(phi-psi))/cos(delm3+psi)))^2);
for R2=0:0.1:3
if (R2>=0 && R2<=1)
delm2=0.5*(1-R2)*delta;
k2=(2*cos(phi-psi)^2)/(cos(phi-psi)^2*(1+R2)+cos(psi)*cos(delm2+psi)*(1-R2)*(1+sqrt((sin(phi+delm2)*sin(phi-psi))/cos(delm2+psi)))^2);
else
delm2=0.5*(R2-1)*delta;
k2=1+0.5*(R2-1)*((cos(phi-psi)^2/(cos(psi)*(cos(delm2+psi)*(-sqrt((sin(phi+delm2)*sin(phi-psi))/(cos(delm2+psi)))+1)^2)))-1);
end
end
for R4=0:0.1:3
if (R4>=0 && R4<=1)
delm4=0.5*(1-R4)*delta;
k4=(2*cos(phi-psi)^2)/(cos(phi-psi)^2*(1+R4)+cos(psi)*cos(delm4+psi)*(1-R4)*(1+sqrt((sin(phi+delm4)*sin(phi-psi))/cos(delm4+psi)))^2);
else
delm4=0.5*(R4-1)*delta;
k4=1+0.5*(R4-1)*((cos(phi-psi)^2/(cos(psi)*(cos(delm4+psi)*(-sqrt((sin(phi+delm4)*sin(phi-psi))/(cos(delm4+psi)))+1)^2)))-1);
end
end
%For horizontal forces
H2=matlabFunction(k2*y1*cos(delm2));
h2=gma*x^2*integral(H2,0,1);
H4_a=matlabFunction(k4*y2*cos(delm4));
H4_b=matlabFunction(cos(delm4)*k4);
h4=gma*y^2*integral(H4_a,0,1)+gma*(x+h)*y*integral(H4_b,0,1);
H3_a=matlabFunction(k3*y2*cos(delm3));
H3_b=matlabFunction(k3*cos(delm3));
h3=gma*y^2*integral(H3_a,0,1)+gma*x*y*integral(H3_b,0,1);
HF=h2-h4+h3-pg-pq;
%
M2=matlabFunction(k2*y1*cos(delm2)*(1-y1));
m2=gma*x^3*integral(M2,0,1);
M4_a=matlabFunction(k4*y2^2*cos(delm4));
M4_b=matlabFunction(k4*y2*cos(delm4));
m4=gma*y^3*integral(M4_a,0,1)+gma*(x+h)*y^2*integral(M4_b,0,1);
M3_a=matlabFunction(k3*y2^2*cos(delm3));
M3_b=matlabFunction(k3*y2*cos(delm3));
m3=gma*y^3*integral(M3_a,0,1)+gma*x*y^2*integral(M3_b,0,1);
MF=m2+m4-m3-pg*(h+x)*(1/3)-0.5*pq*(h+x);
% The Newton-Raphson iterations starts here
del=1;
indx=0;
g=[HF; MF];
J=jacobian([HF, MF], [x, y]);
Z=zeros(2,numel(Q));
for i=1:numel(Q)
del=1;
indx=0;
while del>1e-6
gnum = vpa(subs(g,[x,y,q],[a(1),a(2),Q(i)]));
Jnum = vpa(subs(J,[x,y,q],[a(1),a(2),Q(i)]));
delx = -Jnum\gnum;
a = a + delx;
del = max(abs(gnum));
indx = indx + 1;
end
Z(:,i)=double(a)
end
% 'NEWTON-RAPHSON SOLUTION CONVERGES IN ITERATIONS',indx,
% 'FINAL VALUES OF a ARE';a,

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by Star Strider
on 31 May 2019
 Accepted Answer

The argument in ‘H4_b’ is not a function of anything.
Inserting this line just before the ‘H4_b’ assignment:
H4_b_query = cos(delm4)*k4
produces:
H4_b_query =
9.32591844224377e+000

  2 Comments

Sign in to comment.


Answer by Geoff Hayes
on 31 May 2019

Akshay - what can you tell us about the signature for the matlabFunction? You say that Undefined function 'matlabFunction' for input arguments of type 'double'. which works for all calls (to it) except for H4_b. If we look at
H4_a=matlabFunction(k4*y2*cos(delm4));
H4_b=matlabFunction(cos(delm4)*k4);
the only difference to the input (into this function) is the y2 factor. Note that y2 has been defined as a sym
syms y1 y2 x y q
which suggests (along with the error message) that matlabFunction is expecting a symbolic input data type and not a double input data type. Perhaps your equation for k4 is incorrect or you will need to update matlabFunction to accept non-symbolic inputs.

  1 Comment

The matlabFunction function is part of Symbolic Math Toolbox, and at least the first input to that function must be a symbolic object.
Both delm4 and k4 are double scalars, which means the result of that expression is also a double scalar.

Sign in to comment.