how to write polynomial code

23 visualizzazioni (ultimi 30 giorni)
Ahmad Dalabeeh
Ahmad Dalabeeh il 21 Ott 2017
Risposto: Krishan Kumar il 28 Set 2020
how to write a code that:
- Reads any polynomial P
- Finds its roots.
- Shows the degree of the polynomial.
- Calculates P^3 - Plots the polynomials P and P^3 on a suitable domain specified by the user

Risposta accettata

Birdman
Birdman il 21 Ott 2017
syms x
p(x)=x^2+2*x-3;%as an example
Coeff=coeffs(p(x))';
Coeff=wrev(Coeff);
Roots=roots(Coeff);%roots
Degree=length(Coeff)-1;%degrees
disp(p^3)%calculates p^3
x=0:0.1:1;
plot(x,p(x));grid on;%plots
  3 Commenti
Birdman
Birdman il 21 Ott 2017
Thank you Walter, nice to learn.
Ahmad Dalabeeh
Ahmad Dalabeeh il 21 Ott 2017
thank you very much brothers

Accedi per commentare.

Più risposte (1)

Krishan Kumar
Krishan Kumar il 28 Set 2020
syms x p(x)=x^2+2*x-3;%as an example Coeff=coeffs(p(x))'; Coeff=wrev(Coeff); Roots=roots(Coeff);%roots Degree=length(Coeff)-1;%degrees disp(p^3)%calculates p^3 x=0:0.1:1; plot(x,p(x));grid on;%plots

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by