Assigning a symbolic expression with sprintf command

2 次查看(过去 30 天)
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