list values in symbolic function, a simplification problem

2 ビュー (過去 30 日間)
Adrian Szatmari
Adrian Szatmari 2013 年 1 月 27 日
Dear all,
I have a Matlab function fct.m that returns a symbolic function. Inside the fct.m file, I create a vector, say
A = [1 2 3 4];
Then I declare
syms x y;
f = sym('A(1)+A(2)*x+A(3)*x+A(4)*x*y');
and I return f as the output of fct.m .
The problem I have now is that I obtain in the command window
f =
A(1)+A(2)*x+A(3)*x+A(4)*x*y
However, I would like to know what the A(1), ..., A(4) are and subsequently use Matlab to simplify f. However, Matlab does not seem to understand that A(1), ..., A(4) are actual numbers. As an example I would like to see
f =
1 + 2*x + 3*x + 5*x*y
and get f = 1 + 5*x*(1+y) after simplification.
I would appreciate any help with this. Obviously the A(i)'s are not given by me, but rather computed with another function call.
Thanks in advance,
dodo

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 1 月 27 日
編集済み: Azzi Abdelmalek 2013 年 1 月 27 日
Why to not write it like:
A = [1 2 3 4];
syms x y;
f = A(1)+A(2)*x+A(3)*x+A(4)*x*y

その他の回答 (1 件)

Adrian Szatmari
Adrian Szatmari 2013 年 1 月 27 日
Thanks, yes I figured out that this actually works, instead of giving a function as an output, just give the vector as the output, and then write a script instead of a Matlab function.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by