Assigning a symbolic expression with sprintf command

조회 수: 5 (최근 30일)
Lucas Carvalho
Lucas Carvalho 2017년 5월 13일
댓글: Karan Gill 2017년 5월 14일
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
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by