Solving linear expression with syms
Show older comments
This is the symplification of the code I'm working on. I have 2 problems:
1 - If you run this code, you will see that the matrix D has quite large
numbers. I would like to see those numbers simplified.
(i.e. (1958266807048006347*a)/144115188075855872 becomes 13.5882*a)
2 - After this, all I need is compute the X in A*X = b.
In this expression, A is a matrix where my entries containing an 'a'
are in the first column, the ones containing 'b' in the second and the
one containing 'c' in the third column. b is the vector containing all
the entries without any 'a', 'b' or 'c'*.
syms a b c x y
func = a*log(x) + b*cos(x) + c*exp(x);
phi = (func - y)^2
dphida = diff(phi,a,1);
dphidb = diff(phi,b,1);
dphidc = diff(phi,c,1);
expand(dphida);
expand(dphidb);
expand(dphidc);
x1 = [0.24, 0.65,0.95, 1.24, 1.73, 2.01, 2.23, 2.52, 2.77, 2.99 ];
y1 = [0.23, -0.26, -1.10, -0.45, 0.27, 0.10, -0.29, 0.24, 0.56, 1.00];
for i=1:length(x1)
A(i) = subs(expand(dphida),[x,y],[x1(i),y1(i)]);
B(i) = subs(expand(dphidb),[x,y],[x1(i),y1(i)]);
C(i) = subs(expand(dphidc),[x,y],[x1(i),y1(i)]);
end
A1 = sum(A(1,:));
B1 = sum(B(1,:));
C1 = sum(C(1,:));
D = [A1; B1; C1]
Answers (1)
Walter Roberson
on 19 Mar 2013
0 votes
Use vpa() to convert the rational constants into fixed-point constants.
Categories
Find more on Conversion Between Symbolic and Numeric in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!