solving symbolic equations with partial derivatives

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 Comments

Hi Luca,
I have updated the code to properly define the equations and solved them, please see below.
syms zf zr L Cf(zf, zr);
% Define theta explicitly as a function of zf, zr, and L
theta = @(zf, zr, L) (zf - zr) / L;
% Calculate partial derivatives of Cf with respect to zf and zr
Cf_zf = diff(Cf, zf);
Cf_zr = diff(Cf, zr);
% Define the equations with the correct variables
eqn1 = Cf_zf == diff(Cf, zf);
eqn2 = Cf_zr == diff(Cf, zr);
% Solve the equations
S = solve([eqn1, eqn2]);
The above code defines symbolic variables zf, zr, L, and a function Cf(zf, zr). It then explicitly defines theta as a function of zf, zr, and L. Next, it calculates the partial derivatives of the function Cf with respect to zf and zr using the diff() function. Two equations (eqn1 and eqn2) are defined based on these derivatives. Finally, the code aims to solve these equations using the solve() function to find the values that satisfy both equations simultaneously.
This corrected approach should resolve the issues and allow you to compute the desired derivatives and solve the equations effectively. Adjust the `Cf` function and additional calculations as per your specific problem requirements. Please let me know if you have further questions.
The equations (1) and (2) read
eqn1 = diff(Cf, zf) == diff(Cf, zf);
eqn2 = diff(Cf, zr) == diff(Cf, zr);
What's the sense of it ?
Even if it worked, what do you want to solve for ?
@Torsten,
In the provided equations, eqn1 and eqn2 seem to be defining relationships involving the derivative of Cf with respect to zf and zr. The expressions diff(Cf, zf) and diff(Cf, zr) calculate the derivative of Cf with respect to zf and zr, respectively. The comparison == checks if these derivatives are equal to each other. This type of equation setup is commonly used in mathematical modeling or optimization scenarios where relationships between variables need to be defined and analyzed. Please if you have better way to solve it, then provide solution to this problem. 🙏
I don't even know what @LUCA D'AMBROSIO wants to solve for. But trying to solve two equations that in principle read expr1 == expr1 and expr2 == expr2 is not senseful in my opinion.
@Torsten,
While solving equations like expr1 == expr1 and expr2 == expr2 may seem trivial, they play a crucial role in establishing foundational truths in mathematics and logic. They ensure consistency, validate assumptions, and serve as essential building blocks for more sophisticated reasoning and problem-solving. By recognizing their importance, one can appreciate their relevance in various fields and contexts where precision, correctness, and logical integrity are paramount. Also, we supposed to help each other by providing examples and help understand each other by sharing knowledge rather than critique people’s work. For example, if I were you, I would say hi Umar, maybe I think this approach seems to solve problem better, what do you think, or there is an alternative way to solve this problem, let me show an example. Again, I do appreciate your contribution.
thanks to both of you for your help.
i understand that this problem is a bit trivial in the way i enunciated it: it is part of a bigger problem i am trying to solve for my thesis and this part concerns with the expression of the derivatives of the coefficient of lift Cf in two reference systems, (zf, zr) and (z, theta) related in the way i wrote in the initial question. basically, i have to express the derivatives Cf/theta and Cf/z as functions of Cf/zf and Cf/zr as i can calculate the latter numerically from another code, given some other parameters that here are not needed.
this change of variables from (zf, zr) to (z, theta) is fundamental to validate the model i am trying to develop.
I must solve this symbolically, but i can't find a way to make the change of variables effective in the presence of partial derivatives
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.

Sign in to comment.

Answers (2)

You need to create a function, theta, and express the other functions in terms of theta, and then use functionalDerivative
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) = 

Asked:

on 9 Jul 2024

Commented:

on 11 Jul 2024

Community Treasure Hunt

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

Start Hunting!