필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Trouble creating function out of variable in terms of x

조회 수: 1 (최근 30일)
John Phelan
John Phelan 2020년 3월 11일
마감: MATLAB Answer Bot 2021년 8월 20일
For my project, I need to create a polynomial using divided differences. I sucessfuly can create the polynomial, but I do not know how to turn this polynomial into a funcion. I created this polynomial by adding to matrices together.
E= sym(zeros(n,1));
b=2;
d=1;
if b<n
for a=1:1:n
p=(x-B(1,a));
d=p*d;
E(a,1)=d;
end
b=b+1;
end
F= sym(zeros(n,1));
m=1;
while m<n+1
if m<2
F(m,1) = C(m,1);
end
if m>1
F(m,1) = C(m,1)*E(m,1);
end
m=m+1;
end
w=1;
poly=0;
while w<n+1
addon=F(w,1);
poly=poly+addon;
w=w+1;
end
  댓글 수: 1
John Phelan
John Phelan 2020년 3월 11일
I get a correct polynomial ouput for "poly", but I cannot plug in an x term for poly. For example, poly(2) does not work. I am pretty sure that this is just because of the type of variable I am using.
Also I take numbers from matrices B and C which I do not include here.

답변 (1개)

Peter O
Peter O 2020년 3월 11일
Is there any particular reason it needs to be using symbolic math?
MATLAB has a built-in polynomial evaluation function called polyval. See if you can structure your problem to take advantage of that for evaluation.
  댓글 수: 1
John Phelan
John Phelan 2020년 3월 11일
I am not purposely using symbolic math. To be honest, I am very new to using MAT LAB.
However, I am not sure if using polyval is the best approach here. For my x values, I need them in the form (x-1)*(x-2)... etc. So I don't think it would be easy to covert that to the form needed for polyval
I am wondering how I can convert my answer in terms of x variables to the correct form that can be turned into a function.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by