is it possible to square every element in equation ?
2 ビュー (過去 30 日間)
古いコメントを表示
Hi Im working with inverse kinematics, and with that there are one move where I need to square every element of a quite large equation, are there a way to do this without writing it in everywhere ?
Example
if i have (a+b+c*d) i would lik it to become (a^2+b^2+c^2*d^2), preferably without writing in'^2' everywhere by hand.
Thanks in advance :)
2 件のコメント
Jan
2014 年 4 月 4 日
What exactly does "i have (a+b+c*d)" mean? Is it written on paper, a string, Matlab code or a symbolic Mupad equation?
採用された回答
Azzi Abdelmalek
2014 年 4 月 4 日
編集済み: Azzi Abdelmalek
2014 年 4 月 4 日
syms a b c d
s = (a+b+c.*d)
t=symvar(s);
out=subs(s,t,t.^2)
0 件のコメント
その他の回答 (2 件)
Grzegorz Knor
2014 年 4 月 4 日
You have to use regular expression.
Suppose that you use only small letters, then:
s = '(a+b+c*d)'
expression = '[a-z]'
replace = '$0^2'
s2 = regexprep(s,expression,replace)
0 件のコメント
ragesh r menon
2014 年 4 月 4 日
Yes, This is possible in Symbolic Math Toolbox for example
syms a b c d
s=a+b+c+d;
subs(s, [a b c d],[a^2 b^2 c^2 d^2])
ans =
a^2 + b^2 + c^2 + d^2
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!