solving symbolic equations with partial derivatives

4 次查看(过去 30 天)
hello, I can't find a solution to the following problem: i am trying to solve symbolically some equations which include partial derivatives and a change of reference.
Here is the code:
syms Cf(zf, zr) Cr(zf, zr) theta z L
z = zf;
theta = (zf - zr)/L;
Cf_z = diff(Cf, z);
Cf_f = diff(Cf, zf);
Cf_r = diff(Cf, zr);
Cf_theta = diff(Cf, theta);
Error using sym/diff (line 77)
Second argument must be a variable or a nonnegative integer specifying the number of differentiations.
eqn = [diff(Cf, z)*diff(z, zf) + diff(Cf, theta)*diff(theta, zf) == diff(Cf, zf), diff(Cf, z)*diff(z, zr) + diff(Cf, theta)*diff(theta, zr) == diff(Cf, zr)];
S= solve(eqn)
when i run this, the following error appears:
"Second argument must be a variable or a nonnegative integer specifying the number of differentiations." (@ line 7) because i doesn't recognize theta as a variable of Cf. How can i make the change of reference effective so that it can calculate the partial derivatives of Cf in the new reference z, theta?
thank you very much
  8 个评论
Umar
Umar 2024-7-10
Hi Luca,
To express the derivatives Cf/theta and Cf/z in terms of Cf/zf and Cf/zr, you can utilize the chain rule for partial derivatives. By applying the chain rule effectively, you can relate the derivatives in the two reference systems. Here is a simplified example in MATLAB to demonstrate this concept:
syms Cf Cf_zf Cf_zr z theta
% Define the relationship between Cf, Cf_zf, and Cf_zr
Cf = Cf_zf * some_function(z, theta) + Cf_zr * another_function(z, theta);
% Calculate the derivatives Cf/theta and Cf/z using the chain rule
dCf_dtheta = diff(Cf, theta);
dCf_dz = diff(Cf, z);
By appropriately defining the relationship between Cf, Cf_zf, and Cf_zr and then calculating the derivatives using the diff function in MATLAB, you can express Cf/theta and Cf/z in terms of Cf/zf and Cf/zr symbolically.

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2024-7-10
You need to create a function, theta, and express the other functions in terms of theta, and then use functionalDerivative

Torsten
Torsten 2024-7-10
编辑:Torsten 2024-7-10
syms Cf(zf,zr) cf(z,theta) L
zref = zf;
thetaref = (zf - zr)/L;
dCfdzf = diff(cf,z) * diff(zref,zf) + diff(cf,theta)*diff(thetaref,zf);
dCfdzr = diff(cf,z) * diff(zref,zr) + diff(cf,theta)*diff(thetaref,zr);
% If necessary, write derivatives of coordinate transformation in new
% coordinates
% (not necessary here since derivatives don't depend on zf or zr)
[zfref,zrref] = solve([zref==zf,thetaref==(zf - zr)/L],[zf,zr]);
dCfdzf = subs(dCfdzf,[zf,zr],[zfref,zrref])
dCfdzf(z, theta) = 
dCfdzr = subs(dCfdzr,[zf,zr],[zfref,zrref])
dCfdzr(z, theta) = 

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by