- #1
ver_mathstats
- 260
- 21
- Homework Statement
- We are required to plot y=sqrt(x) on matlab and then interpolate y at 10 evenly spaced points using polyfit and linspace on the interval [0,4].
- Relevant Equations
- y=sqrt(x), polyfit, linspace
My code in Matlab for this practice question is:
(
x = linspace(0,4,10);
y = sqrt(x);
plot(x,y,'-o');
hold on
y2=polyfit(x,y,2);
plot(x,y2,'--or')
)
Is this the best way to do? My plots look nearly identical and are on top of one another but a later question asks to graph the error, so I am unsure if I messed this up because they look identical. Also I am unsure of what my n value should be for polyfit(x,y,n) function, I believe it should be n+1, but am uncertain if this is correct.
(
x = linspace(0,4,10);
y = sqrt(x);
plot(x,y,'-o');
hold on
y2=polyfit(x,y,2);
plot(x,y2,'--or')
)
Is this the best way to do? My plots look nearly identical and are on top of one another but a later question asks to graph the error, so I am unsure if I messed this up because they look identical. Also I am unsure of what my n value should be for polyfit(x,y,n) function, I believe it should be n+1, but am uncertain if this is correct.