Error in function: too many outputs

This is my function code. I need to call it in my main to use cl and cd. I get the same error that there are too many output arguments. Please help i am lost.
%part a
function [cl,cd] = FlatPlate(alpha,Re)
cl1 = 0.5+(4/30)*log10(Re);
alpha1 = 0.576-(0.192/3)*log10(Re);
alpha2 = alpha1 - 0.0698;
cl2 = 0.7*cl1;
K = 0.75*pi;
cd_max = 1.83;
if Re <= 5e5
cd0 = 2.656/(sqrt(Re));
elseif (5e5 < Re) && (Re < 5e7)
cd0 = (0.00375615)+(2.5712025*10^-4)*log10(Re/5e5);
else
cd0 = 0.148/Re^0.2;
end
cd1 = cd0 + K*alpha2^2;
cd2 = cd1 + 2*K*alpha1*(4*pi/180);
A1 = cd_max/2;
B1 = cd_max;
A2 = (tan(alpha2)/cos(alpha2))*(cl2-cd_max*(0.5)*sin(2*alpha2));
B2 = (cd2 - cd_max*sin(alpha2)^2)/cos(alpha2);
if alpha <= alpha1
cl = (cl1/alpha1)*alpha;
cd = cd0+K*(alpha)^2;
elseif alpha > alpha1
cl = cl1 + (cl2-cl1)/(alpha2-alpha1)*(alpha-alpha1);
cd = cd1 +(cd2-cd1)/(alpha2-alpha1)*(alpha-alpha1);
else
cl = A1*sin(2*alpha)+A2*((cos(alpha)^2)/(sin(alpha)));
cd = B1*sin(alpha)^2+B2*cos(alpha);
end
end
%HW 5 - MAIN
clear
clc
c = 3;
B = 4;
rho = 1.2;
visc = 15.2e-6;
V0 = 1.3;
tsr = 2.6;
r = 0.7;
R = 15;
theta = 16;
w = (tsr*V0)/R;
a = 0.0001;
aP = 0;
anew = 0;
aPnew = 0;
x = ((1-a)*V0)/((1+aP)*w*r);
phi = atan(x); %nothing to do w/ geometry
Vrel = sqrt(((1-anew)*V0)^2+((1+aPnew)*w*r)^2);
Re = (Vrel*c)/visc;
sigma = (B*c)/(2*pi); %solidity
%cl = FlatPlate(alpha, Re);
%cd = FlatPlate(alpha, Re);
[cl, cd] = FlatPlate(alpha, Re);
F = (2/pi)*acos(exp(-(B/2)*((R-r)/(r*sin(phi))))); %tip loss factor
Ct = cl*sin(phi)-cd*cos(phi); % tangential force coeff
Cn = cl*cos(phi)-cd*sin(phi); %axial (normal) force coeff
CT = (sigma*(1-a)^2*Cn)/((sin(phi))^2);
if a<0.3
anew = 4*a*F*(1-a);
else
anew = 1/((4*F*(sin(phi))^2)/(sigma*Ct)+1);
end
aPnew = 1/((4*F*sin(phi)*cos(phi))/(sigma*Ct)-1);
disp('The coefficient of thrust is ')
disp(CT)
disp('new a is ')
disp(anew)
disp('new a prime is ')
disp(aPnew)

Antworten (1)

Walter Roberson
Walter Roberson am 16 Apr. 2020

0 Stimmen

You have not defined alpha as a variable, so in your call
[cl, cd] = FlatPlate(alpha, Re);
you are accidentally invoking the function named alpha which happens to not be permitted to have any output arguments.
My guess:
alpha = anew;
and that you want to be calling in a loop to plot a trajectory.

4 Kommentare

Lexie Baylor
Lexie Baylor am 16 Apr. 2020
So should i put alpha = anew in my main?
Walter Roberson
Walter Roberson am 16 Apr. 2020
I suspect so. But I do not know what alpha represents in your code and whether it has any relationship to anew. Like is alpha intended to be the "current" version of the variable and anew is intended to be the updated version?
Lexie Baylor
Lexie Baylor am 16 Apr. 2020
Hi, they do not have any correlation together like that. Alpha is a variable that is used to calculate anew.
Walter Roberson
Walter Roberson am 16 Apr. 2020
Then you should initialize it to whatever value it is intended to have.

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 16 Apr. 2020

Kommentiert:

am 16 Apr. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by