How to set a polynomial as a variable
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Andrei Bobrov
le 26 Juil 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 commentaires
Voir également
Catégories
En savoir plus sur Polynomials dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!