Reputation: 363
Why is the number 0.9947 written 8959626780035403/9007199254740992 in the symbolic function P and what can I do to change it back to 0.9947?
syms x;
f = sin(x);
f = matlabFunction(f);
n = 3;
a = -pi/2;
b = pi/2
X = linspace(a, b, n + 1);
Y = f(X);
y = MetDirecta(X,Y)
syms x Pn
P = 0;
for i = 1:n+1
P = P + (y(i))*x^(i - 1);
end
P
function [y] = MetDirecta(X, Y)
n = length(X);
for i = 1:n
A(i,1) = 1;
end
for i = 1:n
for j = 2:n
A(i,j) = X(i)^(j - 1);
end
end
solutie = GaussPivTot(A, Y');
y = solutie;
end
Upvotes: 0
Views: 40
Reputation: 381
The symbolic math in matlab wants to provide you an exact representation. You can convert the result to a float with double()
.
https://www.mathworks.com/help/symbolic/double.html
Upvotes: 2