I am getting error "not enough input arguments" , I don't know how to resolve this.

function [dn]=numparticles(t, n)
global SECT funcall No m
funcall=funcall+1;
dn=zeros(SECT,1);
sums=zeros(3,1);
disp(['Function call ', num2str(funcall),' t value ', num2str(t) ,' of ',num2str(120),'.'])
for i=1:SECT
if (i-2 >= 1)
for j=1:i-2
sums(1)=sums(1)+beta(i-1,j)*2^(j+1-i)*n(j);
end
end
if (i-1 >= 1)
for j=1:i-1
sums(2)=sums(2)+beta(i,j)*2^(j-i)*n(j);
end
dn(i)=dn(i)+ n(i-1)*sum(1)+ 0.5*beta(i-1,i-1)*n(i-1)^2-n(i)*sums(2);
end
if (i+1 <=SECT)
% dn(i)=dn(i)+2*gamma(i+1)*n(i+1);
for j=1:SECT
sums(3)=sums(3)+beta(i,j)*n(j);
end
dn(i)=dn(i)-n(i)*sums(3);
end
dn(i)=dn(i)/No(1);
sums=zeros(3,1);
end

댓글 수: 1

Jan
Jan 2021년 6월 30일
편집: Jan 2021년 6월 30일
Whenever you mention an error in the forum, post the complete message. It is hard to guess, in which line your code fails, but you have this valuable information directly on the screen. So please share it with the readers.
Is beta a function or an array?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2021년 6월 30일
편집: Jan 2021년 6월 30일
How do you call this function? If you use the green triangle in the editor, the function is called without inputs and you will see the mentioned error.
You have to call it with inputs from the command window or from another script or function:
t = ???;
n = ???;
dn = numparticles(t, n)

댓글 수: 3

I am using this numparticles in another code which is dn.m
global SECT funcall m No
relerr=1e-5;
funcall=0;
massinput = 8; %total mass of solid (kg)
d0= 0.2e-3; %particle diameter (m)
densp = 2500; %particle density (kg/m3)
Vo = pi/6*d0^3; %particle volume
massofone = densp*Vo; %mass of one particle (density*volume)
startnum= massinput/massofone; %Initial N naught
SECT = 7; % Number of sections
m=1;
No=zeros(SECT,1);
No(1)=startnum;
[t, N]=ode15s('numparticles',[0 120],No);
%%
% Plots the
figure
for ii=1:size(N)
plot(1:SECT,N(ii,:),'r');
xlabel('No. of Sections');
ylabel('No. of Particles');
pause(3/100);
end
function [dn]=numparticles (t, n)
global SECT funcall No m
funcall=funcall+1;
dn=zeros(SECT,1);
sums=zeros(3,1);
disp(['Function call ', num2str(funcall),' t value ', num2str(t) ,' of',num2str(120),'.'])
for i=1:SECT
if (i-2 >= 1)
for j=1:i-2
sums(1)=sums(1)+beta(i-1,j)*2^(j+1-i)*n(j);
end
end
if (i-1 >= 1)
for j=1:i-1
sums(2)=sums(2)+beta(i,j)*2^(j-i)*n(j);
end
dn(i)=dn(i)+ n(i-1)*sum(1)+ 0.5*beta(i-1,i-1)*n(i-1)^2-n(i)*sums(2);
end
if (i+1 <=SECT)
% dn(i)=dn(i)+2*gamma(i+1)*n(i+1);
for j=1:SECT
sums(3)=sums(3)+beta(i,j)*n(j);
end
dn(i)=dn(i)-n(i)*sums(3);
end
dn(i)=dn(i)/No(1);
sums=zeros(3,1);
end
function B=beta(i,j)
beta0 = 1; %initial guess
B = beta0.*1/4.*(2+((i/j)^(1/3))+((j/i)^(1/3))); %brownian motion kernel
end
end
If I change the line:
[t, N]=ode15s('numparticles',[0 120],No);
to
[t, N]=ode15s(@numparticles,[0 120],No);
the code runs in Matlab r2021a.
A small acceleration of the code:
function B = beta(i,j)
k = (i/j) ^ (1/3);
B = 0.25 * (2 + k + 1/k)
end
thank you so much, now it is working

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Solar Power에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 6월 30일

댓글:

2021년 6월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by