Error with "too many output arguments" using function "gradient"

% %Step 1 Simulate true data
n=1e5;
mu_L=5000;%mm
sigma_L=100;%mm
mu_E=210e3;%N/mm^2
sigma_E=2000;%N/mm^2
mu_I=17500e4;%mm^4
sigma_I=10000;%mm^4
mu_A=136e2;%mm^2
sigma_A=1500;%mm^2
mu_fy=275;%N/mm^2
sigma_fy=30;%N/mm^2
%load
mu_load=2e6;
sigma_load=2e4;
%Simulate the true data
ui=rand(11,n);
uL=ui(1,:);%geometrical prop for experimental resistance data
uE=ui(2,:);%material prop for experimental resistance data
uI=ui(3,:);%geometrical prop for experimental resistance data
uA=ui(4,:);%geometricalprop for experimental resistance data
ufy=ui(5,:);%material prop for experimental resistance data
utL=ui(6,:);%geometrical prop for theoretical resistance data
utE=ui(7,:);%material prop for theoretical resistance data
utI=ui(8,:);%geometrical prop for theoretical resistance data
utA=ui(9,:);%geometricalprop for theoretical resistance data
utfy=ui(10,:);%material prop for theoretical resistance data
uload=ui(11,:);
L_e=mu_L-sqrt(2)*erfcinv(2*uL)*sigma_L;
E_e=mu_E-sqrt(2)*erfcinv(2*uE)*sigma_E;
I_e=mu_I-sqrt(2)*erfcinv(2*uI)*sigma_I;
A_e=mu_A-sqrt(2)*erfcinv(2*uA)*sigma_A;
fy_e=mu_fy-sqrt(2)*erfcinv(2*ufy)*sigma_fy;
L_t=mu_L-sqrt(2)*erfcinv(2*utL)*sigma_L;
E_t=mu_E-sqrt(2)*erfcinv(2*utE)*sigma_E;
I_t=mu_I-sqrt(2)*erfcinv(2*utI)*sigma_I;
A_t=mu_A-sqrt(2)*erfcinv(2*utA)*sigma_A;
fy_t=mu_fy-sqrt(2)*erfcinv(2*utfy)*sigma_fy;
alpha=0.34; %buckling curve b, buckling along y-y axis
Ncr_e=((pi())^2)*E_e.*I_e./(L_e.^2);
lamda_bar_e=sqrt(A_e.*fy_e./Ncr_e);
phi_e=0.5*(1+alpha*(lamda_bar_e-0.2)+lamda_bar_e.^2);
chi_e=1./(phi_e+sqrt(phi_e.^2-lamda_bar_e.^2));
Nb_Rd_e=chi_e.*A_e.*fy_e;
alpha=0.34; %buckling curve b, buckling along y-y axis
Ncr_t=((pi())^2)*E_t.*I_t./(L_t.^2);
lamda_bar_t=sqrt(A_t.*fy_t./Ncr_t);
phi_t=0.5*(1+alpha*(lamda_bar_t-0.2)+lamda_bar_t.^2);
chi_t=1./(phi_t+sqrt(phi_t.^2-lamda_bar_t.^2));
Nb_Rd_t=chi_t.*A_t.*fy_t;
b=sum(Nb_Rd_e.*Nb_Rd_t)/sum(Nb_Rd_t.^2);
plot(Nb_Rd_t,Nb_Rd_e)
%The true b value is used to generate samples
%calculate the characteristic resistance according to eurocode Annex D
error=Nb_Rd_e./(b*Nb_Rd_t);
%Take natural log
delta=log(error);
%estimated value of expected value of error
delta_bar=sum(delta)/n;
%estimated error variance
error_var=(sum(delta-delta_bar)^2)/(n-1);
%coefficient of variance of error
v_delta=sqrt(exp(error_var^2)-1);
%Assessment via the characteristic value
Xd_L=mu_L*(1-1.64*sigma_L/mu_L);%kn chosen as 1.64 due to large no. of tests
Xd_E=mu_E*(1-1.64*sigma_E/mu_E);
Xd_I=mu_I*(1-1.64*sigma_I/mu_I);
Xd_A=mu_A*(1-1.64*sigma_A/mu_A);
Xd_fy=mu_fy*(1-1.64*sigma_fy/mu_fy);
alpha=0.34; %buckling curve b, buckling along y-y axis
Ncr_t=((pi())^2)*E_t.*I_t./(L_t.^2);
lamda_bar_t=sqrt(A_t.*fy_t./Ncr_t);
phi_t=0.5*(1+alpha*(lamda_bar_t-0.2)+lamda_bar_t.^2);
chi_t=1./(phi_t+sqrt(phi_t.^2-lamda_bar_t.^2));
Nb_Rd_t=chi_t.*A_t.*fy_t;
%summation of variance
%partial derivative of L
[pL,pE,pI,pA,pfy]=gradient(Nb_Rd_t);
sum_var=((pL*sigma_L).^2)+((pE*sigma_E).^2)+((pI*sigma_I).^2)+((pA*sigma_A).^2)+((pfy*sigma_fy).^2);
%resistance evaluated using mean values of basic variables
alpha=0.34; %buckling curve b, buckling along y-y axis
Ncr_m=((pi())^2)*mu_E.*mu_I./(mu_L.^2);
lamda_bar_m=sqrt(mu_A.*mu_fy./Ncr_m);
phi_m=0.5*(1+alpha*(lamda_bar_m-0.2)+lamda_bar_m.^2);
chi_m=1./(phi_m+sqrt(phi_m.^2-lamda_bar_m.^2));
Nb_Rd_m=chi_m.*mu_A.*mu_fy;
%coefficient of variation Vrt
v_rt_square=sum_var/(Nb_Rd_m^2);
%coefficient of variation Vr_square
vr_square=v_delta^2+v_rt_square;
%Q
Q=sqrt(log(vr_square+1));
%rk
rk=b*Nb_Rd_m*exp(-1.64*Q-0.5*(Q^2))
end end
I want to evaluate the partial derivative of Nb_Rd_t with respect to five different variables L_t, E_t, I_t, A_t, fy_t. These variables are 1 by 1e5 vectors. I do not understand why there are too many output arguments. Thanks for your answers in advance!!

3 Comments

@allen leung: we cannot run a screenshot. We cannot edit a screenshot. We cannot search a screenshot. We cannot use a screenshot in any meaninglful way.
Please upload your actual code text by clicking the paperclip button.
Also please shows us the complete error message. This means all of the red text.
Prefer to post code as text using the "{} Code" button. This is usually more convenient than a screenshot.
Sorry for causing you convenience guys! I have just inserted the code and attached my m file here. Thanks!

Sign in to comment.

 Accepted Answer

gradient is a built-in function, which has as many outputs as the input has dimensions. See:
whos gradient -all
Use a different name for your function, e.g. "myGradient".

5 Comments

I have got 5 inputs which in theory I should have 5 outputs. May I know why I still the error 'too many output arguments'? I am a matlab fresh learner so I hope I can given more guidance. Thanks!
Use the debugger to examine to cause of the problems - type this in the command window:
dbstop if error
Now run the code again. When it stops at the error message, check the size of the locally used variables, e.g. in the command window or in the Workspace Browser. You will see:
size(Nb_Rd_t)
>> [1 x 10000]
If you provide a vector as input, gradient cannot reply 5 outputs - exactly as the error message tells already.
@Jan Thanks for your reply! May I know what can I do if I reli want to get the partial derivatives with respect to those 5 variables?
To which 5 variables? You provide a [1 x 10000] vector currently. I cannot know, what you want to do instead.
These 5 variables L_t, E_t, I_t, A_t and fy_t contribute to the value of Nb_Rd_t through these equations. All the variables are 1x10000 vectors. I understand gradient doesn't work in this case. But may I know if there is other solution to find out the partial derivatives corresponding to these variables?
if true
% alpha=0.34; %buckling curve b, buckling along y-y axis
Ncr_t=((pi())^2)*E_t.*I_t./(L_t.^2);
lamda_bar_t=sqrt(A_t.*fy_t./Ncr_t);
phi_t=0.5*(1+alpha*(lamda_bar_t-0.2)+lamda_bar_t.^2);
chi_t=1./(phi_t+sqrt(phi_t.^2-lamda_bar_t.^2));
Nb_Rd_t=chi_t.*A_t.*fy_t;
end

Sign in to comment.

More Answers (0)

Asked:

on 9 Aug 2018

Commented:

on 11 Aug 2018

Community Treasure Hunt

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

Start Hunting!