How would one go about defining polynomials in MATLAB?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Husnain Khalil
el 26 de Feb. de 2018
Comentada: Husnain Khalil
el 26 de Feb. de 2018
1. Define P1=s^6+7s^5+2s4+9s^3+10s^2+12^s+15,
P2=s^6+9s^5+8s^4+9s^3+12s^2+15s+20
I have tried to create a row matrix and use polyval but because s is an undefined value I'm unsure how to proceed from there.
2 comentarios
Torsten
el 26 de Feb. de 2018
No s needed.
Take a look at the example under
https://de.mathworks.com/help/matlab/ref/polyval.html
Best wishes
Torsten.
Respuesta aceptada
Image Analyst
el 26 de Feb. de 2018
Try this:
s = linspace(-1, 1, 500);
P1=s.^6+...
7 * s .^ 5+...
2 * s .^ 4+...
9 * s .^ 3+...
10 * s .^ 2+...
12 * s + 15;
plot(s, P1, 'b-', 'LineWidth', 2);
grid on;
P2=s .^ 6 + ...
9 * s .^ 5 + ...
8 * s .^ 4 + ...
9 * s .^ 3 + ...
12 * s .^ 2 + ...
15 * s + 20;
hold on;
plot(s, P2, 'r-', 'LineWidth', 2);
legend('P1', 'P2');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179448/image.png)
2 comentarios
Image Analyst
el 26 de Feb. de 2018
Editada: Image Analyst
el 26 de Feb. de 2018
Or this:
s = linspace(-1, 1, 500);
coefficients1=[1 7 2 9 10 12 15]
P1 = polyval(coefficients1, s);
plot(s, P1, 'b-', 'LineWidth', 2);
grid on;
coefficients2 = [1 9 8 9 12 15 20]
P2 = polyval(coefficients2, s);
hold on;
plot(s, P2, 'r-', 'LineWidth', 2);
legend('P1', 'P2');
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots 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!