Changing varibles in a Matrix to Values

1 次查看(过去 30 天)
below is the problem I am trying to solve in MatLab. Everything works for computation of these matrix, but once I try to replace the variables with numbers I am receiving errors, or the answers are still in fraction form and pi isn't replaces by the number. Instead it still says cos(2*pi) for example. I would appreciate any help with this. Thanks for your time
syms r E G b h t A Ay Iz Iy alpha theta
LambdaQBt=[cos(alpha),sin(alpha),0;-sin(alpha),cos(alpha),0;0,0,1]
LambdaQB=transpose(LambdaQBt)
HQB=[1,0,0;0,1,0;-r*(1-cos(alpha)),r*sin(alpha),1]
HQBt=transpose(HQB)
TQB=(LambdaQBt*HQB)
fuq=[1/(E*A),0,0;0,1/(G*Ay),0;0,0,1/(E*Iz)]
TQBt=(HQBt*LambdaQB)
Product=(TQBt*fuq*TQB)
fBA=int(Product,alpha,0,theta)
r=3 E=200*10^9 G=77*10^9 b=.1 h=.0866 t=.01 Ay=.0049 Iz=(t*(b^3))/12 Iy=0 A=3*b*t
F=[10000;-5000;10000]
vB=fBA*F
  3 个评论
Stephen23
Stephen23 2018-8-16
编辑:Stephen23 2018-8-16
If the symbolic expression does not contain any symbolic variables without values, then use double to convert a symbolic expression to a numeric value:
double(...)
Note that vB still depends on alpha, so this will not work for the above question, but it might be useful for others who find this thread.
Steven Lord
Steven Lord 2018-8-16
To extend Stephen's answer, if the symbolic expression DOES contain any symbolic variables without values you can use the vpa function to approximate the numeric parts.
syms x
oneThird = sym(1)/3;
y = oneThird*x + x^2
vpa(y)

请先登录,再进行评论。

回答(2 个)

Tiasa Ghosh
Tiasa Ghosh 2018-8-16
I guess the answer vB is still a symbolic expression is due to the fact that you have assigned numerical values to r,E,G,b and so on, after the fBA has already been evaluated as a symbolic expression. So in the last line when you compute fBa*F , the answer is obviously a symbolic expression.

Christopher Creutzig
Assigning values to MATLAB variables does not affect symbolic expressions that have variables of the same name inside. Use the subs command instead. Or start with the concrete values instead of symbolic indeterminates.

Community Treasure Hunt

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

Start Hunting!

Translated by