Assigning a symbolic expression with sprintf command
이전 댓글 표시
Hello guys, I'm trying to implement a code where I define a symbolic function and I want to find out its partial derivatives (first and second) also in a symbolic way. The example is below:
prompt = ('\n Type the function: ');
f = sym(input(prompt,'s'));
prompt = ('\n Type the number of independent variables: ');
n1 = (input(prompt));
n2=n1;
for i=1:1:n1
syms(sprintf('x%d', i));
syms(sprintf('df%d', i));
for j=1:1:n2
syms(sprintf('df%d%d', i,j));
end
end
For n=2, I get the following result (all symbolic variables): x1, x2, df1, df2, df11, df12, df21 and df22.
Now I want to assign to each of these variables the proper partial derivative, for example:
df1 = diff(f,x1)
df2 = diff(f,x2)
df11 = diff(df1,x1)
df12 = diff(df1,x2) and so on...
How can I put these diff commands in a loop??
댓글 수: 1
Karan Gill
2017년 5월 14일
To confirm, another user is interactively entering the function? That is, you are not defining the function yourself, correct?
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Common Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!