Assigning a symbolic expression with sprintf command

4 ビュー (過去 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