chain rule with symbolic functions
显示 更早的评论
I define the following symbolic variables:
syms s k mu2(s,k) mu3(s,k) mu4(s,k)
>> mu2(s, k) = 1 + 6*k^2 - 24*k*s^2 + 25*s^4;
>> mu3(s,k) = 108*k^2*s - 468*k*s^3 + 36*k*s + 510*s^5 - 76*s^3 + 6*s;
>> mu4(s,k) = 3 + 3348*k^4 - 28080*s^2*k^3 + 1296*k^3 - 6048*s^2*k^2 ...
+ 252*k^2 - 123720*s^6*k + 8136*s^4*k - 504*s^2*k ...
+ 24*k + 64995*s^8 - 2400*s^6 - 42*s^4 + 88380*k^2*s^4;
>>
>> Scap = mu3(s,k)/mu2(s,k)^3/2
Scap =(108*k^2*s - 468*k*s^3 + 36*k*s + 510*s^5 - 76*s^3 + 6*s)/(2*(6*k^2 - 24*k*s^2 + 25*s^4 + 1)^3)
When I take the 1st derivative of Scap with respect to s I would expect MatLab to apply the chain rule as Scap is not directly a function of s. Instead I get the following:
>> diff(Scap,s)
ans =
(108*k^2 - 1404*k*s^2 + 36*k + 2550*s^4 - 228*s^2 + 6)/(2*(6*k^2 - 24*k*s^2 + 25*s^4 + 1)^3) + (3*(- 100*s^3 + 48*k*s)*(108*k^2*s - 468*k*s^3 + 36*k*s + 510*s^5 - 76*s^3 + 6*s))/(2*(6*k^2 - 24*k*s^2 + 25*s^4 + 1)^4)
How can I have MatLab explicitly apply the chain rule ?
Thank you so much
mauede
采纳的回答
更多回答(2 个)
asma ahmed
2019-3-11
How to answer this question ؟
Recall the Chain Rule for differentiation: GIven a function of the form y = f(g(x)), the derivative is:
y ' = f '(g(x)) * g'(x)
Using the formula above as outlined in the Solution Template, work out the derivative of y = sin^3( x ) (NOTE: This can also be written as (sin x)^3 ). Then check your answer by using the diff command directly on f(g(x)).
syms ; % NOTE below that you have TWO symbolic variables to define this time!
f=@(u) ; % Write f (outer function) as a function of u to minimize confusion
g=@(x) ; % Write g (inner function) as a function of x
df=diff( ); % derivative of f(u)
df_at_g=subs( ); % replace u with g(x)
dg=diff( ); % derivative of g(x)
dy= % Multiply the appropriate parts above for the final answer
dyalt=diff( ) % Differentiate f(g(x)) directly to compare answers
mauede
2015-11-16
编辑:Walter Roberson
2015-11-16
类别
在 帮助中心 和 File Exchange 中查找有关 Special Values 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!