필터 지우기
필터 지우기

is it possible to square every element in equation ?

조회 수: 2 (최근 30일)
adam
adam 2014년 4월 4일
편집: Azzi Abdelmalek 2014년 4월 4일
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
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?
adam
adam 2014년 4월 4일
that should represent a symbolic equation, like:
syms a b c d
equation = a+b+c*d

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
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)

추가 답변 (2개)

Grzegorz Knor
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)

ragesh r menon
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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by