필터 지우기
필터 지우기

How would one go about defining polynomials in MATLAB?

조회 수: 1 (최근 30일)
Husnain Khalil
Husnain Khalil 2018년 2월 26일
댓글: Husnain Khalil 2018년 2월 26일
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
Torsten
Torsten 2018년 2월 26일
No s needed.
Take a look at the example under
https://de.mathworks.com/help/matlab/ref/polyval.html
Best wishes
Torsten.
Husnain Khalil
Husnain Khalil 2018년 2월 26일
Hi Torsten,
Thanks for replying but I'm still unsure how it would work. If I put my code as:
p1=[1 7 2 9 10 12 15] then try and use poly, it does not work.
nor does: poly([1 [6]], [7 [5]], [2 [4]], [9 [3]], [10 [2]], [12 [1]], [15 [0]],[s])
could you provide any further clarification?
Regards,
Husnain Khalil

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2018년 2월 26일
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');
  댓글 수: 2
Image Analyst
Image Analyst 2018년 2월 26일
편집: Image Analyst 2018년 2월 26일
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');
Husnain Khalil
Husnain Khalil 2018년 2월 26일
Thanks, I'm going over the code but the plot makes it much easier to understand what's going on.
Regards,
Husnain Khalil

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by