how to create a symbolic derivative of f(r(x,y),theta(x,y)) and evaluate it

조회 수: 4 (최근 30일)
Hello Community,
i have some more or less complicated funtions, e.g. a simple one:
f(r,theta) = r*(pi*cos(theta)+2*sin(theta));
x = x0 +r*cos(theta);
y = y0 +r*cos(theta);
and I need the symbolic derivative of f with respect to x any y: d f(r(x,y),theta(x,y)) / dx = ....
my code look like this:
syms f f1 f2 r theta x x0 y0 y pi
f = r*(pi*cos(theta)+2*sin(theta));
f1 = x == x0 + r*cos(theta);
f2 = y == y0 + r*sin(theta);
dr_dx = diff(solve(f1,r),x)
dtheta_x = diff(solve(f1,theta),x)
dr_dy = diff(solve(f2,r),y)
dtheta_y = diff(solve(f2,theta),y)
df_r = diff(f,r)
df_theta = diff(f,theta)
but how i could create the desired derivative..

채택된 답변

David Durschlag
David Durschlag 2021년 1월 29일
Let's break down the operations required:
First, solve for theta and r in terms of x and y:
theta_r = solve([x == x0 + r*cos(theta), y == y0 + r*sin(theta)], [theta, r]);
theta_r will be a struct with possible substitutions for theta and r as its properties.
Second, choose the substitutions (in this case, the first ones):
theta_r_subs = [theta_r.theta(1), theta_r.r(1)];
Third, perform the substitution:
fxy = subs(f, [theta, r], theta_r_subs);
Fourth, differentiate:
df_x = diff(fxy, x);
df_y = diff(fxy, y);
Further solutions can be obtained by choosing different substitutions.
--David

추가 답변 (0개)

카테고리

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