필터 지우기
필터 지우기

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 CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by