How can I use vpa() in my MATLAB function to convert a symbolic polynomial into decimal form that displays coefficients in scientific notation (like -2.6228e-06), and where ex

7 visualizaciones (últimos 30 días)
x = (0:9) * pi / 10;
y = cos(x);
polyLagrange(x, y)
z = pi / 7;
syms s
P = polyLagrange(x, y);
double(subs(P, s, z))
ans =
(56195488738499649208603740859375*s^8)/(159723975628756904588584603877376*pi^8) -
(449563909907079855433250627734375*s^9)/(5750063122635248565189045739585536*pi^9) -
(57568907601261883291880162078125*s^7)/(547625059298595101446575784722432*pi^7) -
(232545547737545734655221802959375*s^6)/(182541686432865033815525261574144*pi^6) -
(103007859212782539731692589374375*s^5)/(4381000474388760811572606277779456*pi^5) +
(2967793965259438821539819472994625*s^4)/(730166745731460135262101046296576*pi^4) -
(81756610363852765011123706510025*s^3)/(92001009962163977043024731833368576*pi^3) -
(2802468829707674447343657251698705*s^2)/(567907468902246771870523036008448*pi^2) -
(464084660976021733588348031*s)/(182541686432865033815525261574144*pi) + 1
ans =
0.9010
function i used:
function lag = polyLagrange(x, y)
syms s
z = poly2sym([1, 0], s);
[k, n] = size(x);
[k, m] = size(y);
if m ~= n
disp('Data error')
return
end
v = sym('v', [1, n]);
w = sym('w', [1, n]);
for i = 1:n
v(i) = sym(y(i));
end
for k = 1:n-1
for i = 1:n-k
w(i) = ((z - x(i)) * v(i + 1) - (z - x(i + k)) * v(i)) / (x(i + k) - x(i));
end
for i = 1:n-k
v(i) = w(i);
end
end
lag=expand ( v ( 1 ) ) ;
end
  3 comentarios

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by