Unable to convert expression into double array

조회 수: 3 (최근 30일)
sxj
sxj 2020년 1월 28일
편집: Walter Roberson 2020년 1월 28일
Dear all,
In the code I would like to use sym function to calculate the first-order derivative of functions F1- F4 and calculate the values of the derivative in special points. But I keep getting this error:
"Error using symengine Unable to convert expression into double array.
Error in sym/double (line 692)
Xstr = mupadmex('symobj::double', S.s, 0);
t = 1.1;
phi = 1.2;
eta_S = 2;
eta_N = eta_S*phi;
sigma = 3;
L_S = 1000;
H_S = 500;
L_N = 800;
H_N = 1600;
z_N_up = 0.99;
z_S_up = 0.98;
syms z_S z_N p_S p_N w_S_H w_N_L w_N_H
F1 = 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 = 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 = 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 = 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))];
F11 = diff(F1,z_S);
F21 = diff(F2,z_S);
F31 = diff(F3,z_S);
F41 = diff(F4,z_S);
double(F11)
double(F21)
double(F31)
double(F41)
How can I obtain the numerical values of F11, F21,F31 and F41 given special values of z_S z_N p_S p_N w_S_H w_N_L w_N_H?

채택된 답변

Matt J
Matt J 2020년 1월 28일
One way is to convert the symbolic expression to a function with matlabFunction. Then you can pass values to it as for any function.
  댓글 수: 2
sxj
sxj 2020년 1월 28일
Hey, Matt, Thanks for the quick reply. It works
Matt J
Matt J 2020년 1월 28일
You're welcome, but please Accept-click the answer to certify that it worked.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 1월 28일
편집: Walter Roberson 2020년 1월 28일
Your F21 and F41 involve several variables including w_N_H. You do not assign values to those variables, so you cannot convert the expression to numeric values.

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by