フィルターのクリア

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