subs in symbolic equation
2 views (last 30 days)
Show older comments
Saeed Heysiattalab
on 21 May 2021
Answered: Hrishikesh Borate
on 25 May 2021
Hello.
I have calculated a partial derivative of a function as following:
clear
clc
syms x y r t real
f = @(r,t) r.*cos(t);
df_r = diff(f,r);
df_t = diff(f,t);
r = @(x,y) sqrt(x.^2 + y.^2);
dr_x = diff(r,x);
t = @(x,y) atan(y,x);
dt_x = diff(t,x);
df_x = df_r*dr_x + df_t*dt_x
the result is :
df_x =
(x*cos(t))/(x^2 + y^2)^(1/2) + (r*y*sin(t))/(x^2 + y^2)
How can I get the df_x in only r and t. I would like to substititute x^2+y^2 with r^2, x with r*cos(t) and y with r*sin(t).
Thanks
0 Comments
Accepted Answer
Hrishikesh Borate
on 25 May 2021
Hi,
It’s my understanding that you are trying to obtain df_x in terms of r and t. Following addition to the existing code will do the same:-
syms r t
df_x = subs(df_x, x.^2+y.^2, r.^2);
df_x = subs(df_x, [x,y], [r*cos(t),r*sin(t)]);
0 Comments
More Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!