Expressing polynomial including a indefinite parameter

2 ビュー (過去 30 日間)
Cagas Akalin
Cagas Akalin 2021 年 10 月 21 日
編集済み: Matt J 2021 年 10 月 21 日
Hi All,
I know that the expression p=[1 -4 2] corresponds to p(x) = x^2 - 4x + 2.
I want to express p(x) = a*x^2 - 4x + 2-a
I would appreciate it if you told me how to do that.
Bests,
Cagdas

採用された回答

Matt J
Matt J 2021 年 10 月 21 日
編集済み: Matt J 2021 年 10 月 21 日
One way.
p = @(x,a) polyval([a,-4,2-a],x);
Usage:
x=1; a=2;
p(x,a)
ans = -2
  5 件のコメント
Matt J
Matt J 2021 年 10 月 21 日
編集済み: Matt J 2021 年 10 月 21 日
But what I am aiming to do is to give it a value only for x which returns a polynomial including the constant(indefinite) "a".
I maintain that that is what is achieved by doing as follows (updated for your new example).
Pxa = @(x) @(a) polyval([2*a,-4,2-a],x);
Now if we invoke px() at x=1,
p=Pxa(1); %x=1
then I claim that p(a) is the polynomial function a-2. We can check various inputs a to verify that this is true:
a=5; p(a)
ans = 3
a=2; p(a)
ans = 0
a=0; p(a)
ans = -2
Cagas Akalin
Cagas Akalin 2021 年 10 月 21 日
Thank you Matt,
It works.
Bests,
Cagdas

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2021 年 10 月 21 日
編集済み: Matt J 2021 年 10 月 21 日
Possibly you mean that you want a coefficient vector as the output, rather than a polynomial in functional form.
syms a x
P = 2*a*x^2 - 4*x + 2-a
P = 
p=subs(P,x,1)
p = 
coefficients = sym2poly(p)
coefficients = 1×2
1 -2
  3 件のコメント
Cagas Akalin
Cagas Akalin 2021 年 10 月 21 日
Dear Matt,
Since my question covers an different topic in the bigger picture I will pose it in an another question page.
Bests,
Cagdas
Matt J
Matt J 2021 年 10 月 21 日
編集済み: Matt J 2021 年 10 月 21 日
Yes, what I was trying to implement was exactly that you guessed.
I'm glad we converged, but please Accept-click the answer to indicate that your question was resolved.
Since my question covers an different topic in the bigger picture I will pose it in an another question page.
Yes, by all means.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by