How to call specific number from polyfit

2 views (last 30 days)
Hello,
How does one call a specific number from the polyfit below? I'd like to do O27fifth = p(27), but this does not work/isn't right.
T = [0 8 16 24 32 40];
Oxy = [14.621 11.843 9.870 8.418 7.305 6.413];
p = polyfit(T,Oxy, 5);
figure(2)
plot(t,polyval(p,t))
title('fifth order polynomial')
%need Oxy when T = 27
%sfprintf('Oxy(27) = %0.41f\n',O27fifth);

Accepted Answer

Star Strider
Star Strider on 11 Mar 2021
Try this:
T = [0 8 16 24 32 40];
Oxy = [14.621 11.843 9.870 8.418 7.305 6.413];
p = polyfit(T,Oxy, 5);
pv27 = polyval(p,27);
figure(2)
plot(T,polyval(p,T), 27,pv27,'xr')
title('fifth order polynomial')
text(27,pv27, sprintf('(%d, %.2f)\n\\downarrow',27,pv27),'vert','bottom','horiz','left')
.

More Answers (1)

David Hill
David Hill on 11 Mar 2021
T = [0 8 16 24 32 40];
Oxy = [14.621 11.843 9.870 8.418 7.305 6.413];
p = polyfit(T,Oxy, 5);
figure(2);
plot(T,Oxy,0:.1:40,polyval(p,0:.1:40));
pAt27=polyval(p,27);

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!