Borrar filtros
Borrar filtros

solving symbolic equations with partial derivatives

53 visualizaciones (últimos 30 días)
LUCA D'AMBROSIO
LUCA D'AMBROSIO el 9 de Jul. de 2024 a las 18:11
Comentada: LUCA D'AMBROSIO el 11 de Jul. de 2024 a las 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
  8 comentarios
Umar
Umar el 10 de Jul. de 2024 a las 9:17
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
LUCA D'AMBROSIO el 11 de Jul. de 2024 a las 16:04
thank you

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 10 de Jul. de 2024 a las 1:06
You need to create a function, theta, and express the other functions in terms of theta, and then use functionalDerivative

Torsten
Torsten el 10 de Jul. de 2024 a las 10:58
Editada: Torsten el 10 de Jul. de 2024 a las 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) = 

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by