solving symbolic equations with partial derivatives

12 views (last 30 days)
LUCA D'AMBROSIO on 9 Jul 2024
Commented: LUCA D'AMBROSIO on 11 Jul 2024 at 16:04
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
Umar on 10 Jul 2024
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.
LUCA D'AMBROSIO on 11 Jul 2024 at 16:04
thank you

Walter Roberson on 10 Jul 2024
You need to create a function, theta, and express the other functions in terms of theta, and then use functionalDerivative
LUCA D'AMBROSIO on 11 Jul 2024 at 16:04
thank you

Torsten on 10 Jul 2024
Edited: Torsten on 10 Jul 2024 at 13:17
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) =
LUCA D'AMBROSIO on 11 Jul 2024 at 16:04
thank you