Why do I get the error message : 'Too Many Output Arguments' when I try to execute a function?

3 views (last 30 days)
Here I attached my files:
function [f]=hanu(~,y)
%f=y(1); G=y(2); H=(3); I=y(5); J=y(6); K=y(7); M=y(4)
k=0.5;
B=0.5;
we=3;
n=0.2;
J=0.2;
Pr=2;
L=0.5;
Sc=1.2;
f=zeros(7,1);
f(1)=G;
f(2)=H;
f(3)=(G^2-F*H-2*k*H)*(1+we^2*H^2)^((n-1)/2)-k*(n-1)*we^2*H^3*(1+we^2*H^2)^((n-3)/2)+B*G/((1+2*k*eta)*(1+we^2*H^2)^((n-1)/2)+(n-1)*we^2*H^2*(1+2*k*eta)*(1+we^2*H^2)^(n-3)/2);
f(4)=I;
f(5)=(-2*k*I)-Pr*I*y(1)/(1+2*k*eta);
f(6)=K;
f(3)=(L*J*(1-J)^2-K*y(1)-(2/Sc)*k*K)/((1/Sc)*1+2*eta*k);
f=[f(1) f(2) f(3) f(4) f(5) f(6) f(7) ];
end
-------------------------------------------->
function basefluid(N,albha,beta,gamma)
%f=h1; G=h2; H=h3; I=h5; J=h6; K=h7; M=h4
% Boundary conditions f(0)=0; G(0)=1; G(inf)=1; M(0)=1; M(inf)=0; J(inf)=1; K(0)=Ls*J(0)
%Initial approximation H(0)=-1; I(0)=1; K(0)=1;
p=0; q=1; h=(b-a)/N;
i=0;
for i=p:h:q
eta(i+1)= (eta(i)+h);
k1= F1(f(i), G(i), H(i), I(i), J(i), K(i), M(i), eta(i));
l1= F2(f(i), G(i), H(i), I(i), J(i), K(i), M(i), eta(i));
m1= F3(f(i), G(i), H(i), I(i), J(i), K(i), M(i), eta(i));
n1= F4(f(i), G(i), H(i), I(i), J(i), K(i), M(i), eta(i));
o1= F5(f(i), G(i), H(i), I(i), J(i), K(i), M(i), eta(i));
p1= F6(f(i), G(i), H(i), I(i), J(i), K(i), M(i), eta(i));
q1= F7(f(i), G(i), H(i), I(i), J(i), K(i), M(i), eta(i));
k2= F1(f(i)+1/4*h*k1, G(i)+1/4*h*l1,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)+1/2*h);
k5= F1(f(i)+3/16*h*k1+9/16*k4*h, G(i)+3/16*h*l1+9/16*l4*h, H(i)+3/16*h*m1+9/16*m4*h, I(i)+3/16*h*n1+9/16*n4*h, J(i)+3/16*h*o1+9/16*o4*h, K(i)+3/16*h*p1+9/16*p4*h, M(i)+3/16*h*q1+9/16*q4*h, eta(i)+3/4*h);
l5= F2(f(i)+3/16*h*k1+9/16*k4*h, G(i)+3/16*h*l1+9/16*l4*h, H(i)+3/16*h*m1+9/16*m4*h, I(i)+3/16*h*n1+9/16*n4*h, J(i)+3/16*h*o1+9/16*o4*h, K(i)+3/16*h*p1+9/16*p4*h, M(i)+3/16*h*q1+9/16*q4*h, eta(i)+3/4*h);
m5= F3(f(i)+3/16*h*k1+9/16*k4*h, G(i)+3/16*h*l1+3/16*l4*h, H(i)+3/16*h*m1+9/16*m4*h, I(i)+3/16*h*n1+9/16*n4*h, J(i)+3/16*h*o1+9/16*o4*h, K(i)+3/16*h*p1+9/16*p4*h, M(i)+3/16*h*q1+9/16*q4*h, eta(i)+3/4*h);
n5= F4(f(i)+3/16*h*k1+9/16*k4*h, G(i)+3/16*h*l1+3/16*l4*h, H(i)+3/16*h*m1+9/16*m4*h, I(i)+3/16*h*n1+9/16*n4*h, J(i)+3/16*h*o1+9/16*o4*h, K(i)+3/16*h*p1+9/16*p4*h, M(i)+3/16*h*q1+9/16*q4*h, eta(i)+3/4*h);
o5= F5(f(i)+3/16*h*k1+9/16*k4*h, G(i)+3/16*h*l1+3/16*l4*h, H(i)+3/16*h*m1+9/16*m4*h, I(i)+3/16*h*n1+9/16*n4*h, J(i)+3/16*h*o1+9/16*o4*h, K(i)+3/16*h*p1+9/16*p4*h, M(i)+3/16*h*q1+9/16*q4*h, eta(i)+3/4*h);
p5= F6(f(i)+3/16*h*k1+9/16*k4*h, G(i)+3/16*h*l1+3/16*l4*h, H(i)+3/16*h*m1+9/16*m4*h, I(i)+3/16*h*n1+9/16*n4*h, J(i)+3/16*h*o1+9/16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(i)+ h/90*(7*q1+32*q3+12*q4+32*q5+7*q6);
end
end
--------------------------------------------------------------------------------------------------------->
% Newton's Method
N=1000;
albha=-1;
beta=1;
gamma=1;
yb=0.1;
Error=1;
while Error >=1e-5
[x,f]=Newfun(albha,beta,gamma);
albha = albha-(f(1,3)-yb)/f(1,4)
beta = beta-(f(5,1)-yb)/f(5,2)
gamma = gamma-(f(7,1)-yb)/f(7,2)
Error =abs(f(1,3)-yb)
Error =abs(f(5,1)-yb)
Error =abs(f(7,3)-yb)
end
plot(x,f(:,2))

Answers (2)

Cris LaPierre
Cris LaPierre on 11 Sep 2022
What function are you trying to call that is giving you the error? The code you shared doesn't use either of the functions you have defined.
The error means you have called a function with more output variables than the function returns. Consider this example.
% Call function with a single output variable
A=f(1)
A = 2
% Your error - call function with more outputs than the function returns
[A,B] = f(1)
Error using solution>f
Too many output arguments.
% function has one output, out
function out = f(in)
out = in+1;
end

Image Analyst
Image Analyst on 11 Sep 2022
Why are you doing this
function [f]=hanu(~,y)
instead of this
function [f]=hanu(y)
That doesn't make sense to me.
Also, what is the line of code where you are calling and what is the complete error message (line number, line of code, error description - everything. ALL THE RED TEXT)?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Categories

Find more on Data Import from MATLAB 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!

Translated by