Write a script that calculates the user produced polynomial. The polynomial can be input until the user decides to terminate the program.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ivan Roko Cavka
el 29 de En. de 2020
Hello,
I've been given an asignment in school and I'm a bit stuck with this task in the title.
Can anyone help me write the script because I don't know how to create a polynomial that is user decided and loop it at the same time?
Thanks in adwance.
2 comentarios
Matt J
el 29 de En. de 2020
Editada: Matt J
el 29 de En. de 2020
Once you've written something, we can help fix things. As a hint, the following would be one way to read in a vector of polynomial coefficients, e.g,
>> p = input('\nEnter polynomial coefficients: ')
Enter polynomial coefficients: [1,2,1]
p =
1 2 1
Respuesta aceptada
Matt J
el 29 de En. de 2020
Editada: Matt J
el 29 de En. de 2020
If you have the Symbolic Math Toolbox and wish to manipulate the polynomials in symbolic form, you can use poly2sym,
>> p = input('\nEnter polynomial coefficients: ')
Enter polynomial coefficients: [1,1,0,-1]
p =
1 1 0 -1
>> P=poly2sym(p)
P =
x^3 + x^2 - 1
However, that's often unnecessary. There are many Matlab commands that can analyze polynomials given only a vector representing their coefficients, e.g.,
>> roots(p) %roots of the polynomial
ans =
-0.8774 + 0.7449i
-0.8774 - 0.7449i
0.7549 + 0.0000i
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!