Passing the numeric matrix to symbolic function

3 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(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.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by