How do I differentiate this function?

조회 수: 1 (최근 30일)
Leandro Nitsch
Leandro Nitsch 2019년 3월 26일
댓글: Torsten 2019년 3월 27일
Hi guys,
I am new to MATLAB and have the following problem: I programmed the following function
I took derivatives by hand but then I wanted MATLAB to take the derivatives for me with respect to independent variables K, NRC, X, R and NRM. Somehow I always get the following error message when using the diff function:
Error using sym/subsindex (line 769)
Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic
variables and the body of the function is a SYM expression. When indexing, the input must be numeric,
logical, or ':'.
Error in
@(K,NRC,NRM,R,X)Z*K^gamma((1-eta)*((1-alpha)*NRC^{EOS1}+alpha*(X^v+R^v)^{EOS1/v})^{EOS2/EOS1}+eta*NRM^{EOS2})^{(1-gamma)/EOS2}
Error in sym>funchandle2ref (line 1308)
S = x(S{:});
Error in sym>tomupad (line 1206)
x = funchandle2ref(x);
Error in sym (line 179)
S.s = tomupad(x);
Error in sym/privResolveArgs (line 921)
argout{k} = sym(arg);
Error in sym/diff (line 21)
args = privResolveArgs(S,varargin{:});
By the way my code is the following:
>> gamma=0.3;
eta=0.11;
alpha=0.3;
v=0.6;
EOS2=0.00001;
EOS1=-1;
Z=1;
syms K NRC NRM R X
Y=@(K,NRC,NRM,R,X) Z*K^gamma((1-eta)*((1-alpha)*NRC^{EOS1}+alpha*(X^v+R^v)^{EOS1/v})^{EOS2/EOS1}+eta*NRM^{EOS2})^{(1-gamma)/EOS2};
partial1 = diff(Y,K);
What am I doing wrong?
Thanks for your answer!

채택된 답변

Torsten
Torsten 2019년 3월 26일
syms Z K gamma eta alpha NRC EOS1 v X R EOS2 NRM
Y= Z*K^gamma*((1-eta)*((1-alpha)*NRC^EOS1+alpha*(X^v+R^v)^(EOS1/v))^(EOS2/EOS1)+eta*NRM^(EOS2))^((1-gamma)/EOS2);
dYdK = diff(Y,K)
  댓글 수: 2
Leandro Nitsch
Leandro Nitsch 2019년 3월 27일
Hi Torsten,
Thank you for your anwer. I did what you suggested but am still getting the same error message :/
Torsten
Torsten 2019년 3월 27일
For me, the code as written works.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by