Passing the numeric matrix to symbolic function

2 ビュー (過去 30 日間)
Vishakha Ramani
Vishakha Ramani 2018 年 2 月 14 日
コメント済み: Vishakha Ramani 2018 年 2 月 14 日
Hello,
I have created a function containing symbolic expressions. The expressions make use of a symbolic matrix. I want to solve the function passing the numeric matrix which replaces the symbolic matrix and provides a numeric answer. I can't seem to understand how to pass the numeric matrix.
function example
R= sym('R',[3 3])
r_b= R([1 2], [3])
R_bar= R([1 2], [1 2])
R_til=R([2 3],[2 3])
syms alpha_bar beta_bar
a_bar= [1;alpha_bar]
b_bar= [beta_bar;1]
P= sym(R_bar*a_bar)
Q= sym(R_til*b_bar)
syms E_a E_b
u_bar= [1; 0]
v_bar= [0;1]
W = sym(E_a*u_bar)
X= sym(E_b*v_bar)
C= sym(P==W)
D= sym(Q==X)
[alpha_bar_, E_a_] = solve(P==W,[alpha_bar,E_a])
[beta_bar_, E_b_] = solve(Q==X,[beta_bar,E_b])
a_bar= [1;alpha_bar_]
b_bar=[beta_bar_;1]
delta= (a_bar)'*r_b
gamma_b = delta/E_b_
gamma_a= delta/E_a_
a= [a_bar;0]-(gamma_b*[0;b_bar])
b= [0;b_bar]-gamma_a*[a_bar;0]
end
My R is R= [1 1 0; 1 3 2; 0 2 3].
Any help on this example would be deeply appreciated.
Thank You.

採用された回答

Karan Gill
Karan Gill 2018 年 2 月 14 日
You're not passing any arguments to the function. To learn that, see function.
If you want a numerical result, instead of a symbolic solver like solve, use a numeric solver like vpasolve or fsolve.
Lastly, any numeric input can be converted to symbolic form by using sym(input).
  2 件のコメント
Vishakha Ramani
Vishakha Ramani 2018 年 2 月 14 日
I read the link provided by you and converted numeric input to symbolic form. The solution worked. Thank you very much.
Karan Gill
Karan Gill 2018 年 2 月 14 日
Glad to hear that!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 2 月 14 日
subs(a, R, NumericR)
and you might want to double() the results.
You need to avoid assigning a numeric value to R itself for this to work.
  1 件のコメント
Vishakha Ramani
Vishakha Ramani 2018 年 2 月 14 日
I wanted to pass the numeric matrix from the command window. I passed the appropriate arguments to the function and it worked. Thank you so very much for the help.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by