Undefined function 'm' for input arguments of type 'double

Hi, I don't know why I keep getting this error..I've made deep search on the forum but I got no solution.. Here's my function:
function [x,y,vx,vy,t] = ss(gx,gy,hx,hy,t0,tN,x0,y0,vx0,vy0,B,N)
%step size%
dt=(tN-t0)/(N-1);
%arrays%
t=linspace(t0,tN,N);
ax=zeros(B,N);
ay=zeros(B,N);
vx=zeros(B,N);
vy=zeros(B,N);
x=zeros(B,N);
y=zeros(B,N);
for i = 1:B
x(i,1)=x0(i);
y(i,1)=y0(i);
vx(i,1)=vx0(i);
vy(i,1)=vy0(i);
end
for i = 1:B % body number %
%Initial acceleration
for k = 1:N-1
for j = 1:B % rest of bodies%
if j==i %nothing%
else
ax(i,k)=ax(i,k)+gx(x(j,k)-x(i,k),y(j,k)-y(i,k),m(j));
ay(i,k)=ay(i,k)+gy(x(j,k)-x(i,k),y(j,k)-y(i,k),m(j));
end
end
%tmid = t(k)+dt/2;
xmid = x(i,k)+hx(vx(i,k)).*(dt/2); %????
ymid = y(i,k)+hy(vy(i,k)).*(dt/2); %????
vxmid = vx(i,k)+ax(i,k).*(dt/2);
vymid = vy(i,k)+ay(i,k).*(dt/2);
for j = 1:B % rest of bodies%
if j==i %nothing%
else
ax(i,k)=ax(i,k)+gx(x(j,k)-xmid,y(j,k)-ymid,m(j));
ay(i,k)=ay(i,k)+gy(x(j,k)-xmid,y(j,k)-ymid,m(j));
end
end
x(i,k+1) = x(i,k)+hx(vxmid).*dt; %????
y(i,k+1) = v(i,k)+hy(vymid).*dt; %????
vx(i,k+1) = vx(i,k)+ax(i,k).*dt;
vy(i,k+1) = vy(i,k)+ay(i,k).*dt;
end
end
Here's the script:
%Initial values
G=1 ;
B=2 ;
m=[40000;87777] ;
ax=zeros(B,1);
ay=zeros(B,1);
t0=0 ;
tN=365 ;
x0=[5;98765] ;
y0=[8975647;86] ;
vx0=[2;3] ;
vy0=[4,5] ;
N=10 ;
gx = @ (x,y,m) ((G.*m.*x)./(((x.^2)+(y.^2)).^(3/2)));
gy = @ (x,y,m) ((G.*m.*y)./(((x.^2)+(y.^2)).^(3/2)));
hx = @ (x,y,m) (vx);
hy = @ (x,v,m) (vy);
[x,y,vx,vy,t] = ss(gx,gy,hx,hy,t0,tN,x0,y0,vx0,vy0,B,N);
And the error is...
Undefined function 'm' for input arguments of type 'double'.
Error in ss (line 27)
ax(i,k)=ax(i,k)+gx(x(j,k)-x(i,k),y(j,k)-y(i,k),m(j));
Thanks in advance!

 Accepted Answer

You have a reference to m(j) in the subject line but there's no definition of a variable m in the function nor is it in the argument list. Hence, to Matlab the expression m(j) looks like a function which you don't have one of, either.
If (as I presume) it's intended to be an array of masses (given the comment on acceleration and bodies), then pass it as another argument.

2 Comments

Yeah, I can see it now, damn... Thank you very much!
Unfortunately I'll probably have more errors...

Sign in to comment.

More Answers (1)

Error seems straight forward to me ... once you reach that line m is not defined, hence the error. Is m supposed to be a vector containing the mass of the objects, and you forgot to define it?

Categories

Find more on Functions 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!