Reputation: 74
I've noticed that after the substitution of numeric 'float'
values in a symbolic matrix, the conversion is in a fractional form with very large values, that I want to avoid:
A=(uvw(1,:)-bMat(1,:)).^2+(uvw(2,:)-bMat(2,:)).^2+(uvw(3,:)-bMat(3,:)).^2-legStroke.^2;
A=subs(A,[x,y,z,phi,theta,psi],...
[1.37,0.0,0.0,degtorad(0.0),degtorad(-1.32),degtorad(0.0)]);
A=simplify(A)
and I get as result the following:
A=[((9004809005642893*p1x)/9007199254740992 - b1x + 137/100)^2-l1^2 +(44086462975326147772185208371001*p1x^2)/83076749736557242056487941267521536 + ...
I tried to use sym(A,'d')
or similar, following some tips from the web, but I got this error message:
Error in sym>tomupad (line 2232)
assumptions(S,x.s,a);
Upvotes: 1
Views: 419
Reputation: 18484
You cannot apply sym(A,'d')
if A
is already a symbolic expression (i.e., in terms of unknown symbolic variables, class sym
or symfun
). The purpose of sym(A,'d')
is to convert a numeric values and arrays into symbolic form.
You have two options.
1. Use something like sym(A,'d')
to convert your numeric values to inexact symbolic decimal form before they are incorporated into your symbolic expressions. This will result in a loss of accuracy in some cases.
2. Convert your exact symbolic expression to floating-point form at the very end using variable precision arithmetic, i.e., vpa(A)
. This method should be more accurate as your symbolic calculations will be be done exactly (you still need be careful how you do your initial conversion to symbolic, however).
Upvotes: 0