How to simplify a complicated output of a function with only double coefficients
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nilgün Uzun
am 16 Nov. 2022
Kommentiert: Nilgün Uzun
am 16 Nov. 2022
Hello, I am trying yo find the Newton interpolation polynomial for a given equation of f(x). My code runs perfectly except for the output polynomial. Matlab output shows complicated divisions instead of doing this math calculation itself. You can find the part of the code and the output below. I tried to use expand() function and tried to make every number double() inside the code. However, it didnt work. I tried to use double() to the function but I guess I am not allowed to do that. How can I simplify the below function? I would really appriciate any help. Thank you.
syms newton_interpolation_polynomial(x) polyy(x)
newton_interpolation_polynomial(x) = coeff(1);
temp = newton_interpolation_polynomial;
for j=1:n-1 %for loop must continue n-1 times
int=double(coeff(j+1)/coeff(j));
polyy(x) = temp(x)*double(int)*(x-xi(j));
newton_interpolation_polynomial(x) = newton_interpolation_polynomial(x) + polyy(x);
temp = polyy;
end
fprintf('newton interpolation polynomial for %d data points', n);
newtonpolynomial=(newton_interpolation_polynomial)
Output:
newtonpolynomial(x) =
(51375358502237082155643439903779671152671159331*x*(- 5 + x))/5846006549323611672814739330865132078623730171904 -(7671812162478049910275214342399*x)/81129638414606681695789005144064 - (346697575244925906543118474756817083859362140633764486933214125*x*(- 5 + x)*(- 10 + x))/842498333348457493583344221469363458551160763204392890034487820288 + (1857934767430616230828508262867643330923098633854702133777521627238145717458375*x*(- 5 + x)*(- 10 + x)*(- 15 + x))/242833611528216133864932738352939863330300854881517440156476551217363035650651062272 + 1828326789959911/4503599627370496
The name of the file is newtonpolynomial so I want to print the newtonpolynomial(x). It works great, when I plot the graph, it is exactly the graph I wanted to do. But newtonpolynomial(x) looks so complicated. Thanks again for your help.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polynomials finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!