How to convert a sym data type to symfun datatype?

25 ビュー (過去 30 日間)
Nagulavancha Sai Preetham
Nagulavancha Sai Preetham 2023 年 3 月 23 日
編集済み: Manikanta Aditya 2023 年 3 月 23 日
I need to find the value of a function Eq. But the result comes out as an expresssion. The datatype of Eq is sym. How to I change it to symfun to calculate that value?
syms as(q)
A = [1 2 3; 4 5 6; 7 8 9];
B = [2 3 4; 5 6 3; 9 9 10];
P = A - q*B;
Eq = det(P);
C=[3 4 5];
as(q) = 1;
disp(Eq(1));
as = as*poly2sym(C,q)*q;
disp(roots(sym2poly(Eq)));
0.0000 + 0.0000i 0.7949 + 0.2459i 0.7949 - 0.2459i
  3 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 3 月 23 日
What is as(q) supposed to be?
Eq is not an explicit function of a symoblic variable, thus Eq(1) just calls to the first element of Eq, which corresponds to the equation you obtain.
Do you want to substitute the value of q=1 to Eq?
Nagulavancha Sai Preetham
Nagulavancha Sai Preetham 2023 年 3 月 23 日
Yes, I want to substitute q = 1 in Eq. And as(q) is a redundant, so dont worry about it.

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

採用された回答

Manikanta Aditya
Manikanta Aditya 2023 年 3 月 23 日
編集済み: Manikanta Aditya 2023 年 3 月 23 日
Hi Preetham,
As per my understanding, you are interested in finding the value of the expression. So, converting it to a function before finding the value gives the result.
Use the symfun function on the required expression to convert it to a function.
syms as(q)
A = [1 2 3; 4 5 6; 7 8 9];
B = [2 3 4; 5 6 3; 9 9 10];
P = A - q*B;
Eq = symfun(det(P),q);
C=[3 4 5];
as(q) = 1;
disp(Eq(1));
as = as*poly2sym(C,q)*q;
disp(roots(sym2poly(Eq)));
For further reference, please refer to this link to know more about ‘symfun’ function:
I hope this resolves your issue.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by