not enough input arguments when using symbolic

2 ビュー (過去 30 日間)
sxj
sxj 2020 年 2 月 12 日
回答済み: Payas Bahade 2020 年 4 月 13 日
Dear all,
I am using the symbolic function to calculate the derivative of functions and convert the derivative results by "matlabFunction" . After that, I want to obtain the specific value of the derivatives at initial given points, but the error message "not enough input arguments" appear. How can I fix it? I can input the initial value directly and it works, but it looks waste of time.
Besides, How can I simplify the codes where I calculate F11-F71? Does the loop like "for" possibly work?
Thanks a lot!
%clear
%Parameters
t_0 = 1.8;
phi = 1.2;
eta_S = 1;
eta_N = eta_S*phi;
sigma = 3.5;
L_S = 1000;
H_S = 500;
L_N = 800;
H_N = 1600;
z_N_up = 1;
z_S_up = 0.9;
%Derivative
syms z_S z_N p_S p_N w_S_H w_N_L w_N_H t
x = [z_S,z_N,p_S,p_N,w_S_H,w_N_L,w_N_H,t];
I_N = w_N_H*H_N + w_N_L*L_N;
I_S = w_S_H*H_S + L_S;
g1N = [(1-sigma)*log(w_S_H)-1]*[(1-sigma)*log(w_S_H)]^(-2)*[w_S_H^((1-sigma)*(1-z_N))-w_S_H^(1-sigma)];
g1S = [(1-sigma)*log(w_S_H)-1]*[(1-sigma)*log(w_S_H)]^(-2)*[w_S_H^((1-sigma)*(1-z_S))-w_S_H^(1-sigma)];
g2N = [(1-sigma)*log(w_S_H)]^(-1)*[(1-z_N)*(w_S_H)^((1-sigma)*z_N)-1]+[(1-sigma)*log(w_S_H)]^(-2)*[w_S_H^((1-sigma)*z_N)-1];
g2S = [(1-sigma)*log(w_S_H)]^(-1)*[(1-z_S)*(w_S_H)^((1-sigma)*z_S)-1]+[(1-sigma)*log(w_S_H)]^(-2)*[w_S_H^((1-sigma)*z_S)-1];
g3N = [(1-sigma)*log(w_N_H/w_N_L)-1]*[(1-sigma)*log(w_N_H/w_N_L)]^(-2)*[(w_N_H/w_N_L)^((1-sigma)*(1-z_N_up))-(w_N_H/w_N_L)^((1-sigma)*(1-z_N))];
g3S = [(1-sigma)*log(w_N_H/w_N_L)-1]*[(1-sigma)*log(w_N_H/w_N_L)]^(-2)*[(w_N_H/w_N_L)^((1-sigma)*(1-z_S_up))-(w_N_H/w_N_L)^((1-sigma)*(1-z_S))];
g4N = [(1-sigma)*log(w_N_H/w_N_L)]^(-1)*[(1-z_N_up)*(w_N_H/w_N_L)^((1-sigma)*z_N_up)-(1-z_N)*(w_N_H/w_N_L)^((1-sigma)*z_N)]+[(1-sigma)*log(w_N_H/w_N_L)]^(-2)*[(w_N_H/w_N_L)^((1-sigma)*z_N_up)-(w_N_H/w_N_L)^((1-sigma)*z_N)];
g4S = [(1-sigma)*log(w_N_H/w_N_L)]^(-1)*[(1-z_S_up)*(w_N_H/w_N_L)^((1-sigma)*z_S_up)-(1-z_S)*(w_N_H/w_N_L)^((1-sigma)*z_S)]+[(1-sigma)*log(w_N_H/w_N_L)]^(-2)*[(w_N_H/w_N_L)^((1-sigma)*z_S_up)-(w_N_H/w_N_L)^((1-sigma)*z_S)];
F1(x) = z_N*log(w_S_H*w_N_L/w_N_H) - [log(w_N_L)-log(t)-sigma*(sigma-1)^(-1)*log(phi)];
F2(x) = z_S*log(w_S_H*w_N_L/w_N_H) - [log(w_N_L)-log(t)-sigma*(sigma-1)^(-1)*log(phi)];
F3(x) = p_N^(1-sigma) - eta_S^(sigma)*t^(1-sigma)*[(1-sigma)*log(w_S_H)]^(-1)*[w_S_H^(z_N*(1-sigma))-1] - eta_N^(sigma)*w_N_L^(1-sigma)*[(1-sigma)*log(w_N_H/w_N_L)]^(-1)*[(w_N_H/w_N_L)^(1-sigma)-(w_N_H/w_N_L)^(z_N*(1-sigma))];
F4(x) = p_S^(1-sigma) - eta_S^(sigma)*[(1-sigma)*log(w_S_H)]^(-1)*[w_S_H^(z_S*(1-sigma))-1] - eta_N^(sigma)*t^(1-sigma)*w_N_L^(1-sigma)*[(1-sigma)*log(w_N_H/w_N_L)]^(-1)*[(w_N_H/w_N_L)^(1-sigma)-(w_N_H/w_N_L)^(z_S*(1-sigma))];
F5(x) = L_S*w_S_H^(1-sigma)*[I_N*p_N^(sigma-1)*t^(-sigma)*g1N+I_S*p_S^(sigma-1)*g1S] - H_S*w_S_H*[I_N*p_N^(sigma-1)*t^(-sigma)*g2N+I_S*p_S^(sigma-1)*g2S];
F6(x) = L_N*w_N_L*w_N_H^(1-sigma)*[I_N*p_N^(sigma-1)*g3N+I_S*p_S^(sigma-1)*t^(-sigma)*g3S] - H_N*w_N_H*w_N_L^(1-sigma)*[I_N*p_N^(sigma-1)*g4N+I_S*p_S^(sigma-1)*t^(-sigma)*g4S];
F7(x) = L_S*phi^(sigma)*w_N_L^(1-sigma)*[I_N*p_N^(sigma-1)*g4N+I_S*p_S^(sigma-1)*t^(-sigma)*g4S] - L_N*w_N_L*[I_N*p_N^(sigma-1)*t^(-sigma)*g2N+I_S*p_S^(sigma-1)*g2S];
% Partial Differential respect to endogenous variables: z_S
F11 = matlabFunction(diff(F1,z_S));
F21 = matlabFunction(diff(F2,z_S));
F31 = matlabFunction(diff(F3,z_S));
F41 = matlabFunction(diff(F4,z_S));
F51 = matlabFunction(diff(F5,z_S));
F61 = matlabFunction(diff(F6,z_S));
F71 = matlabFunction(diff(F7,z_S));
% the value of derivatives at specific given points
x_0 = [0.0210 0.2429 1.5721 0.9723 1.5823 2.3639 1.7306 1.8000];
F21(x_0)
F21(0.0210,0.2429,1.5721,0.9723,1.5823,2.3639,1.7306,1.8000)

回答 (1 件)

Payas Bahade
Payas Bahade 2020 年 4 月 13 日
Hi,
For the first part of the question, following code can be used to pass multiple input arguments to function using cell array:
x_0 = {0.0210 0.2429 1.5721 0.9723 1.5823 2.3639 1.7306 1.8000};
F21(x_0{:})
For second part of question, below lines of code illustrates the use of ‘for’ loop for calculating F11 to F71 which gets stored in variable Fxx:
size=7;
Fx=cell(size,1);
x_0 = {0.0210 0.2429 1.5721 0.9723 1.5823 2.3639 1.7306 1.8000};
for i=1:size
Fi =strcat('F', num2str(i));
Fx{i}= matlabFunction(diff(eval(Fi),z_S));
Fxx{i}=Fx{i}(x_0{:});
end
Hope this helps!

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by