Why bad partial differentiation?

Hi, I've a problem with this:
input parameter to my function is degree-it's number
There is a reason why I need m0,phi0 and not l0
m=sym('m',[1,degree]);
m=[m0 m];
l=sym('l',[degree,1]);
phi=sym('phi',[1,degree]);
phi=[phi0 phi] ;
for i=1:length(phi)
phi(i)=strcat(char(phi(i)),'(t)');
end
B=(1/2)*l(1)*m(2)*diff(phi(1),t)*diff(phi(2),t)*cos(phi(2))
phit=phi(2)
subs(diff(subs(B, phit, 'phit'),'phit'),'phit', phit)
I want to derive according to phi1(t), and the result is 0, but I expect (-1/2)*l1*m1*diff(phi0(t),t)*diff(phi1(t),t)*sin(phi1(t))
BUT, when I derive this B=(1/2)*l(1)*m(2)*diff(phi(1),t)*cos(phi(2)), it's all righ,
Any help would be appreciated

4 件のコメント

Walter Roberson
Walter Roberson 2013 年 3 月 9 日
Note: subs(expression, newvalue, name) is an obsolete syntax that is still supported for backwards compatibility. It should be subs(expression, name, newvalue) as in
subs(S, 'phit', phit)
dodovoscek
dodovoscek 2013 年 3 月 9 日
編集済み: dodovoscek 2013 年 3 月 9 日
I have tried this new syntax but now it doesn't work at all... Do you have any idea how to derive expression B according to phi1(t)?
but thanks for answer
Walter Roberson
Walter Roberson 2013 年 3 月 9 日
Could I ask you to show the value of B before the differentiation ?
dodovoscek
dodovoscek 2013 年 3 月 9 日
B=(1/2)*l1*m1*diff(phi0(t),t)*diff(phi1(t),t)*cos(phi1(t)) and I want to derive it according to phi1(t), but the way I mentioned returns 0,and
result=diff(B,phi(2)) doesnt work at all, just error

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2013 年 3 月 9 日

0 投票

The MuPAD Symbolic Toolbox cannot differentiate with respect to a function. (Maple cannot either.)

5 件のコメント

dodovoscek
dodovoscek 2013 年 3 月 10 日
I am sure this is possible because my friend has older version of matlab and this result=diff(B,phi(2)) command works. Moreover phi1(t) isnt function but time variant variable
Walter Roberson
Walter Roberson 2013 年 3 月 10 日
A "time variant variable" is a function.
A function, in mathematics, is any mapping of a source domain to a range of values. Fundamentally it only needs to be expressible as a set of mappings of individual domain elements. So a function can be something that maps a set of small non-negative integers to values -- i.e., something commonly called a vector of values.
Older versions of MATLAB used the Maple symbolic engine. I have a full version of Maple:
> diff((1/2)*l1*m1*(diff(phi0(t), t))*(diff(phi1(t), t))*cos(phi1(t)), phi1(t))
Error, invalid input: diff received phi1(t), which is not valid for its 2nd argument
I would also note that only R2012a onward support
m=sym('m',[1,degree]);
dodovoscek
dodovoscek 2013 年 3 月 10 日
編集済み: dodovoscek 2013 年 3 月 10 日
OK, my fault, I will find a way how to avoid it, thanks anyway
But i am suspicious why
B=(1/2)*l(1)*m(2)*diff(phi(1),t)*cos(phi(2))
phit=phi(2)
subs(diff(subs(B, phit, 'phit'),'phit'),'phit', phit)
this works and phi(2) is phi1(t)
Walter Roberson
Walter Roberson 2013 年 3 月 10 日
In that case, you are differentiating with respect to a variable, not a function. Keep in mind that you are passing in 'phit' as a string, not phit by value (not quotation marks), so the symbol formed from 'phit' is going to be divorced from the phi(2) that appears in the expression.
The existence of the factor in your original expression of diff(phi(2),t) makes it especially questionable to differentiate a multiple of that factor by phi(2).
dodovoscek
dodovoscek 2013 年 3 月 11 日
Thanks, now everything is clear and I have found a way haw to avoid it :) thaks for your time
Best Regards
Domino

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by