Hi Shivam,
I understand from your query that you need help understanding why the displayed output of the Lagrange polynomial is in rational form rather than decimal form.
Kindly refer to the code snippet from the code you shared. To display the polynomial in decimal form, you should display “r” instead of “s”, as “s” is a symbolic expression that contains the coefficients in rational numbers.
fprintf('Polynomial is \n');
digits(4); %to restrict decimal form to 4 signi. Digit
r = vpa(s); %to represent in decimal form
disp(r); % here instead of ‘s’, as in the code shared by you, ‘r’ the decimal form should be displayed
Here is the obtained output of the code you shared:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1578441/image.png)
Figure 1 Obtained Lagrange Polynomial
Hope this helps,
Regards,
Neelanshu