フィルターのクリア

How to set a polynomial as a variable

3 ビュー (過去 30 日間)
Hosup Song
Hosup Song 2016 年 7 月 26 日
回答済み: Andrei Bobrov 2016 年 7 月 26 日
I'm trying to create an m script that will give me different polynomials as results.
I want to know how to set up the code so that
A = x^2+1
but I won't need the value of x and variable A will remain as a polynomial.
A doesn't have to be a single polynomial, it could be an array of polynomials.
I wish to put this in a for loop so it would be nice to know how.
In the end, the code will resemble something like this
for i = 1:100
syms x
v1 = x^2+1;
v2 = x^5+4;
v3 = x^23-45;
c1 = i;
c2 = i^2;
c3 = i^3;
A{i} = c1*v1+c2*v2+c3*v3;
end
And of course, there will be no value of x because they are all polynomials.
Please help. Thank you.

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2016 年 7 月 26 日
B = zeros(24,3);
B(sub2ind(size(B),[22,24,19,24,1,24],[1,1,2,2,3,3])) = [1,1,1,4,1,-45];
ii = bsxfun(@power,reshape(1:100,1,1,[]),1:3);
A = num2cell(squeeze(sum(bsxfun(@times,ii,B),2)),1);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by