how to create a symbolic derivative of f(r(x,y),theta(x,y)) and evaluate it
2 次查看(过去 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..
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!