Replace powers with a sequence

조회 수: 1 (최근 30일)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022년 1월 26일
댓글: Mohammad Shojaei Arani 2022년 1월 27일
Hello friends!
Consider a binomial symbolic expression like (x-1)^3 and a symbolic vector e of size 3 (e=sym('e',[1 3]) ). Of
course, in my real problem I have 'n' instead of 3 but I just used 3 here for simplicity. If expand (x-1)^3 then I get
(x-1)^3 = x^3-3*x^3+3*x-1;
which includes all powers of x from 0 to 3, as we know. Now, I need to substitute x with e(1), x^2 with e(2), x^3 with e(3).
Unfortunately, I cannot use 'subs' command here since when I try to assign x with e(1), it automatically assigns x^2 with
e(1)^2 and x^3 with e(1)^3 which is not what I want (similarly, if I try to asign x^2 with e(2) it might interfere with other powers
of x).
Ant idea?
Thanks!
Babak
  댓글 수: 2
Rik
Rik 2022년 1월 26일
If by e(k) you mean exp(k), isn't the replacement equivalent to what you want? It might not look tidy, but it is the same number.
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022년 1월 27일
No. I do not mean exp. 'e' is just a symbolic array. If you look at the title of mt post "Replace powers with asequence" you will see that I am not cconsidering a specific sequence.

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

답변 (1개)

Torsten
Torsten 2022년 1월 26일
syms x
c = sym2poly(expand((x-1)^3));
e = sym('e',[3,1]);
c_times_e = c*e

카테고리

Help CenterFile Exchange에서 Formula Manipulation and Simplification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by