Variable calculations with matlab

Hi,
is it possible to get variable expressions in matlab?
For example:
From
>> y = (a+b)^2
Can I get
>> y = a^2+2ab+b^2

 채택된 답변

Walter Roberson
Walter Roberson 2013년 3월 7일

1 개 추천

If you have the Symbolic toolbox,
syms a b
y = expand( (a+b)^2 )

댓글 수: 3

dav
dav 2013년 3월 7일
Thanks a lot Walter.
dav
dav 2013년 3월 7일
I do have it but when I typed y = expand ((1-x)^-1)
the output is -1/(1-x)
How can I expand it using the binomial expansion?
thanks
Walter Roberson
Walter Roberson 2013년 3월 7일
If the output has the leading - sign then that is the wrong expansion for (1-x)^(-1) which is 1/(1-x) with no leading minus sign.
1/(1-x) appears to already be in binomial expansion form to me. There is no Pascal's triangle entry for -1, and if you consider it as 1 divided by the binomial expansion of (1-x)^1 then it is already in the proper form.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by