필터 지우기
필터 지우기

solving symbolic equations with partial derivatives

조회 수: 53 (최근 30일)
LUCA D'AMBROSIO
LUCA D'AMBROSIO 2024년 7월 9일 18:11
댓글: LUCA D'AMBROSIO 2024년 7월 11일 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
Umar
Umar 2024년 7월 10일 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 2024년 7월 11일 16:04
thank you

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2024년 7월 10일 1:06
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일 10:58
편집: Torsten 2024년 7월 10일 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) = 

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by