compute a variable v1 that predicts the voltage at 10 s using the linear fit. in matlab

Assuming you have already performed linear regression using polyfit function and obtained the fitting coefficients p for your data:

main.m
p = polyfit(x,y,1); % 1 is degree of the fit
45 chars
2 lines

You can then compute the predicted voltage at 10 seconds as follows:

main.m
v1 = polyval(p,10);
20 chars
2 lines

This uses the fitted coefficients p to evaluate the polynomial at x=10.

Alternatively, you can also directly extract the slope and intercept a and b of the linear fit, and use them to compute the predicted v1:

main.m
[a,b] = polyfit(x,y,1);
v1 = a*10 + b;
39 chars
3 lines

Here, polyfit returns the coefficients in reverse order, so we extract a as the first element and b as the second element of the output. We then use them to compute v1 as a*10 + b.

related categories

gistlibby LogSnag