How to plot a polynomial function multiplied by a row vector

조회 수: 8 (최근 30일)
Maud
Maud 2014년 11월 17일
댓글: Thorsten 2014년 11월 17일
Hello!
My question is how to make a function file which will plot a polynomial function p(x)=a0+ a1x^1 + a2x^2 + a3x^3 + .... + amx^m.
I know how to plot a polynomial function from this form: 1 + x + x^2 + x^3+ ... + x^M, which is for k = 0:M p = p + x.^k end; plot(x,p);
But I don't know how I can multiply the multiple parts with a certain variable.
Does anyone know how to do this?

답변 (1개)

Thorsten
Thorsten 2014년 11월 17일
for k = 0:M
p = p + a(k+1)*x.^k;
end;
  댓글 수: 2
Maud
Maud 2014년 11월 17일
Thanks! But do you also know how to program it with a as a row vector? For example, when I need to make the function with a series of particular numbers as the variables, so when the number is 9870225, the polynomial function will be : 9 + 8x + 7x^2 + 0x^3 + 2x^4+ 2x^5 + 5x^6
Thorsten
Thorsten 2014년 11월 17일
You can generate the variable "a" from your number as follows
v = 9870225;
N = ceil(log10(v));
for i = 1:N
a(N-i+1) = rem(v, 10);
v = floor(v/10);
end

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by