How to set a polynomial as a variable
3 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Andrei Bobrov
on 26 Jul 2016
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);
0 Comments
See Also
Categories
Find more on Polynomials in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!